diff --git a/Core/Notification/Screenshot/FormNotificationScreenshotable.cs b/Core/Notification/Screenshot/FormNotificationScreenshotable.cs index f58fefa1..1030af69 100644 --- a/Core/Notification/Screenshot/FormNotificationScreenshotable.cs +++ b/Core/Notification/Screenshot/FormNotificationScreenshotable.cs @@ -24,19 +24,26 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback)); browser.LoadingStateChanged += (sender, args) => { - if (!args.IsLoading){ - using(IFrame frame = args.Browser.MainFrame){ - if (!ScriptLoader.ExecuteFile(frame, "screenshot.js")){ - this.InvokeAsyncSafe(callback); - } - } + if (args.IsLoading){ + return; + } + + string script = ScriptLoader.LoadResource("screenshot.js", true); + + if (script == null){ + this.InvokeAsyncSafe(callback); + return; + } + + using(IFrame frame = args.Browser.MainFrame){ + ScriptLoader.ExecuteScript(frame, script.Replace("{width}", ClientSize.Width.ToString()), "screenshot"); } }; - LoadTweet(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty)); SetScreenshotHeight(1); + LoadTweet(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty)); } - + protected override string GetTweetHTML(TweetNotification tweet){ string html = tweet.GenerateHtml("td-screenshot"); diff --git a/Resources/Scripts/screenshot.js b/Resources/Scripts/screenshot.js index 0f84f153..5db14eb7 100644 --- a/Resources/Scripts/screenshot.js +++ b/Resources/Scripts/screenshot.js @@ -1,6 +1,6 @@ (function($TD){ let ele = document.getElementsByTagName("article")[0]; - ele.style.width = window.innerWidth+"px"; + ele.style.width = "{width}px"; ele.style.position = "absolute"; let contentHeight = ele.offsetHeight; @@ -9,6 +9,7 @@ let avatar = ele.querySelector(".tweet-avatar"); let avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0; - $TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9))); - setTimeout($TD.triggerScreenshot, document.getElementsByTagName("iframe").length ? 267 : 67); + $TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9))).then(() => { + setTimeout($TD.triggerScreenshot, document.getElementsByTagName("iframe").length ? 267 : 67); + }); })($TD_NotificationScreenshot);