From 01244ec6328ac1d5b5b823aac2009cf43f2b119f Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Mon, 30 Jul 2018 01:49:38 +0200 Subject: [PATCH] Replace td-example-notification attribute with .td-example body class --- .../Example/FormNotificationExample.cs | 6 ++++-- Core/Notification/FormNotificationBase.cs | 6 ++---- Core/Notification/FormNotificationMain.cs | 12 ++++++++---- Core/Notification/TweetNotification.cs | 16 ++++------------ Resources/Scripts/notification.js | 12 +++++------- Resources/Scripts/styles/notification.css | 6 +++++- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Core/Notification/Example/FormNotificationExample.cs b/Core/Notification/Example/FormNotificationExample.cs index 4edf7a49..ee91652f 100644 --- a/Core/Notification/Example/FormNotificationExample.cs +++ b/Core/Notification/Example/FormNotificationExample.cs @@ -9,7 +9,7 @@ namespace TweetDuck.Core.Notification.Example{ sealed class FormNotificationExample : FormNotificationMain{ public override bool RequiresResize => true; protected override bool CanDragWindow => Config.NotificationPosition == TweetNotification.Position.Custom; - + protected override FormBorderStyle NotificationBorderStyle{ get{ if (Config.NotificationSize == TweetNotification.Size.Custom){ @@ -23,6 +23,8 @@ protected override FormBorderStyle NotificationBorderStyle{ } } + protected override string BodyClasses => base.BodyClasses+" td-example"; + public event EventHandler Ready; private readonly TweetNotification exampleNotification; @@ -36,7 +38,7 @@ public FormNotificationExample(FormBrowser owner, PluginManager pluginManager) : exampleTweetHTML = exampleTweetHTML.Replace("</p>", @"</p><div style='margin-top:256px'>Scrollbar test padding...</div>"); #endif - exampleNotification = TweetNotification.Example(exampleTweetHTML, 176); + exampleNotification = new TweetNotification(string.Empty, string.Empty, "Home", exampleTweetHTML, 176, string.Empty, string.Empty); } private void browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e){ diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs index eef8a0c0..228b0bbe 100644 --- a/Core/Notification/FormNotificationBase.cs +++ b/Core/Notification/FormNotificationBase.cs @@ -10,7 +10,7 @@ using TweetDuck.Core.Utils; namespace TweetDuck.Core.Notification{ - partial class FormNotificationBase : Form, AnalyticsFile.IProvider{ + abstract partial class FormNotificationBase : Form, AnalyticsFile.IProvider{ protected static UserConfig Config => Program.Config.User; protected static int FontSizeLevel{ @@ -186,9 +186,7 @@ public virtual void ResumeNotification(){ } } - protected virtual string GetTweetHTML(TweetNotification tweet){ - return tweet.GenerateHtml(IsCursorOverBrowser ? "td-notification td-hover" : "td-notification", this); - } + protected abstract string GetTweetHTML(TweetNotification tweet); protected virtual void LoadTweet(TweetNotification tweet){ currentNotification = tweet; diff --git a/Core/Notification/FormNotificationMain.cs b/Core/Notification/FormNotificationMain.cs index d5563052..c5f2ae9a 100644 --- a/Core/Notification/FormNotificationMain.cs +++ b/Core/Notification/FormNotificationMain.cs @@ -67,6 +67,8 @@ private int BaseClientHeight{ } } } + + protected virtual string BodyClasses => IsCursorOverBrowser ? "td-notification td-hover" : "td-notification"; public Size BrowserSize => Config.DisplayNotificationTimer ? new Size(ClientSize.Width, ClientSize.Height-timerBarHeight) : ClientSize; @@ -181,9 +183,11 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent } private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){ - if (e.Frame.IsMain && browser.Address != "about:blank"){ - e.Frame.ExecuteJavaScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Environment.Notification)); - ScriptLoader.ExecuteScript(e.Frame, ScriptLoader.LoadResource("notification.js", this), "root:notification"); + IFrame frame = e.Frame; + + if (frame.IsMain && browser.Address != "about:blank"){ + frame.ExecuteJavaScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Environment.Notification)); + ScriptLoader.ExecuteFile(frame, "notification.js", this); } } @@ -247,7 +251,7 @@ public override void ResumeNotification(){ } protected override string GetTweetHTML(TweetNotification tweet){ - string html = base.GetTweetHTML(tweet); + string html = tweet.GenerateHtml(BodyClasses, this); foreach(InjectedHTML injection in plugins.NotificationInjections){ html = injection.InjectInto(html); diff --git a/Core/Notification/TweetNotification.cs b/Core/Notification/TweetNotification.cs index 7ef6975f..4d96bd0e 100644 --- a/Core/Notification/TweetNotification.cs +++ b/Core/Notification/TweetNotification.cs @@ -10,11 +10,7 @@ namespace TweetDuck.Core.Notification{ sealed class TweetNotification{ private const string DefaultHeadLayout = @"<html class=""scroll-v os-windows dark txt-size--14"" lang=""en-US"" id=""tduck"" data-td-font=""medium"" data-td-theme=""dark""><head><meta charset=""utf-8""><link href=""https://ton.twimg.com/tweetdeck-web/web/dist/bundle.4b1f87e09d.css"" rel=""stylesheet""><style type='text/css'>body { background: rgb(34, 36, 38) !important }</style>"; public static readonly ResourceLink AppLogo = new ResourceLink("https://ton.twimg.com/tduck/avatar", ResourceHandler.FromByteArray(Properties.Resources.avatar, "image/png")); - - public static TweetNotification Example(string html, int characters){ - return new TweetNotification(string.Empty, string.Empty, "Home", html, characters, string.Empty, string.Empty, true); - } - + public enum Position{ TopLeft, TopRight, BottomLeft, BottomRight, Custom } @@ -32,11 +28,8 @@ public enum Size{ private readonly string html; private readonly int characters; - private readonly bool isExample; - - public TweetNotification(string columnId, string chirpId, string title, string html, int characters, string tweetUrl, string quoteUrl) : this(columnId, chirpId, title, html, characters, tweetUrl, quoteUrl, false){} - - private TweetNotification(string columnId, string chirpId, string title, string html, int characters, string tweetUrl, string quoteUrl, bool isExample){ + + public TweetNotification(string columnId, string chirpId, string title, string html, int characters, string tweetUrl, string quoteUrl){ this.ColumnId = columnId; this.ChirpId = chirpId; @@ -46,7 +39,6 @@ private TweetNotification(string columnId, string chirpId, string title, string this.html = html; this.characters = characters; - this.isExample = isExample; } public int GetDisplayDuration(int value){ @@ -70,7 +62,7 @@ public string GenerateHtml(string bodyClasses, Control sync){ build.Append(' ').Append(bodyClasses); } - build.Append('\'').Append(isExample ? " td-example-notification" : "").Append("><div class='column' style='width:100%!important;min-height:100vh!important;height:auto!important;overflow:initial!important;'>"); + build.Append("'><div class='column' style='width:100%!important;min-height:100vh!important;height:auto!important;overflow:initial!important;'>"); build.Append(html); build.Append("</div></body>"); build.Append("</html>"); diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js index 70a79e3c..516f2ab7 100644 --- a/Resources/Scripts/notification.js +++ b/Resources/Scripts/notification.js @@ -121,16 +121,14 @@ // // Block: Setup a skip button. // - if (!document.body.hasAttribute("td-example-notification")){ - document.body.children[0].insertAdjacentHTML("beforeend", ` + document.body.children[0].insertAdjacentHTML("beforeend", ` <svg id="td-skip" width="10" height="17" viewBox="0 0 350 600"> <path fill="#888" d="M0,151.656l102.208-102.22l247.777,247.775L102.208,544.986L0,442.758l145.546-145.547"> </svg>`); - - document.getElementById("td-skip").addEventListener("click", function(){ - $TD.loadNextNotification(); - }); - } + + document.getElementById("td-skip").addEventListener("click", function(){ + $TD.loadNextNotification(); + }); // // Block: Setup a hover class on body. diff --git a/Resources/Scripts/styles/notification.css b/Resources/Scripts/styles/notification.css index 5d3776d6..8e258947 100644 --- a/Resources/Scripts/styles/notification.css +++ b/Resources/Scripts/styles/notification.css @@ -104,7 +104,7 @@ html[data-td-font='smallest'] .fullname-badged:before, html[data-td-font='small' vertical-align: sub !important; margin-right: 4px !important; } - + .td-notification-padded .item-img { position: absolute; left: 21px; @@ -159,6 +159,10 @@ html[data-td-font='smallest'] .fullname-badged:before, html[data-td-font='small' transition: opacity 0.15s ease; } +.td-example #td-skip { + display: none; +} + .td-hover #td-skip { opacity: 0.75; }