1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-23 21:15:49 +02:00

Remove HTML styles after copying selected text to clipboard

This commit is contained in:
chylex 2017-01-08 16:36:49 +01:00
parent 50a8893f4f
commit fc77b85083
3 changed files with 29 additions and 0 deletions
Core
Resources/Scripts

View File

@ -166,6 +166,10 @@ public void ScreenshotTweet(string html, int width, int height){
form.InvokeSafe(() => form.OnTweetScreenshotReady(html, width, height));
}
public void FixClipboard(){
form.InvokeSafe(WindowsUtils.ClipboardStripHtmlStyles);
}
public void OpenBrowser(string url){
BrowserUtils.OpenExternalBrowser(url);
}

View File

@ -1,9 +1,13 @@
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace TweetDck.Core.Utils{
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){
string testFile = Path.Combine(path, ".test");
@ -39,5 +43,19 @@ public static Timer CreateSingleTickTimer(int timeout){
timer.Tick += (sender, args) => timer.Stop();
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);
}
}
}

View File

@ -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.
//