mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-02 20:34:07 +02:00
Remove HTML styles after copying selected text to clipboard
This commit is contained in:
parent
50a8893f4f
commit
fc77b85083
@ -166,6 +166,10 @@ public void ScreenshotTweet(string html, int width, int height){
|
|||||||
form.InvokeSafe(() => form.OnTweetScreenshotReady(html, width, height));
|
form.InvokeSafe(() => form.OnTweetScreenshotReady(html, width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void FixClipboard(){
|
||||||
|
form.InvokeSafe(WindowsUtils.ClipboardStripHtmlStyles);
|
||||||
|
}
|
||||||
|
|
||||||
public void OpenBrowser(string url){
|
public void OpenBrowser(string url){
|
||||||
BrowserUtils.OpenExternalBrowser(url);
|
BrowserUtils.OpenExternalBrowser(url);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace TweetDck.Core.Utils{
|
namespace TweetDck.Core.Utils{
|
||||||
static class WindowsUtils{
|
static class WindowsUtils{
|
||||||
|
private static readonly Regex RegexStripHtmlStyles = new Regex(@"\s?(?:style|class)="".*?""");
|
||||||
|
private static readonly Regex RegexOffsetClipboardHtml = new Regex(@"(?<=EndHTML:|EndFragment:)(\d+)");
|
||||||
|
|
||||||
public static bool CheckFolderWritePermission(string path){
|
public static bool CheckFolderWritePermission(string path){
|
||||||
string testFile = Path.Combine(path, ".test");
|
string testFile = Path.Combine(path, ".test");
|
||||||
|
|
||||||
@ -39,5 +43,19 @@ public static Timer CreateSingleTickTimer(int timeout){
|
|||||||
timer.Tick += (sender, args) => timer.Stop();
|
timer.Tick += (sender, args) => timer.Stop();
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ClipboardStripHtmlStyles(){
|
||||||
|
if (!Clipboard.ContainsText(TextDataFormat.Html)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string original = Clipboard.GetText(TextDataFormat.Html);
|
||||||
|
string updated = RegexStripHtmlStyles.Replace(original, string.Empty);
|
||||||
|
|
||||||
|
int removed = original.Length-updated.Length;
|
||||||
|
updated = RegexOffsetClipboardHtml.Replace(updated, match => (int.Parse(match.Value)-removed).ToString().PadLeft(match.Value.Length, '0'));
|
||||||
|
|
||||||
|
Clipboard.SetText(updated, TextDataFormat.Html);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,6 +524,13 @@
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Block: Work around clipboard HTML formatting.
|
||||||
|
//
|
||||||
|
$(document).on("copy", function(e){
|
||||||
|
window.setTimeout($TD.fixClipboard, 0);
|
||||||
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
// Block: Inject custom CSS and layout into the page.
|
// Block: Inject custom CSS and layout into the page.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user