changeset 61:753765f3814e

Not sure why but sometimes link style is null?
author nanaya <me@nanaya.pro>
date Sun, 12 May 2019 01:30:44 +0900
parents cd3ffdc31613
children a065dafbe010
files tweetdeck-large-image.user.js
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tweetdeck-large-image.user.js	Sun May 05 22:36:10 2019 +0900
+++ b/tweetdeck-large-image.user.js	Sun May 12 01:30:44 2019 +0900
@@ -1,7 +1,7 @@
 // ==UserScript==
 // @name         Tweetdeck large image
 // @namespace    https://myconan.net
-// @version      2.0.2
+// @version      2.0.3
 // @description  No more stupid link for images in tweetdeck
 // @author       nanaya
 // @match        https://tweetdeck.twitter.com/*
@@ -46,10 +46,17 @@
     var image = link.querySelector(".media-img");
     var url;
 
+    // sometimes the image is just background image of the link.
+    // strip all query strings and original :size suffix
     if (image == null) {
-      // sometimes the image is just background image of the link.
-      // strip all query strings and original :size suffix
-      url = getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)(?::small)?(?:\?.*)?\1\)$/, "$2");
+
+      var linkStyle = getComputedStyle(link);
+
+      if (linkStyle == null) {
+        return;
+      }
+
+      url = linkStyle.backgroundImage.replace(/^url\(('|")?(.+?)(?::small)?(?:\?.*)?\1\)$/, "$2");
     } else {
       url = image.src.replace(/:[a-z0-9]+(?:\?.*)?$/, "");
     }