Mercurial > ec-userscripts
comparison tweetdeck-large-image.user.js @ 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 |
comparison
equal
deleted
inserted
replaced
| 60:cd3ffdc31613 | 61:753765f3814e |
|---|---|
| 1 // ==UserScript== | 1 // ==UserScript== |
| 2 // @name Tweetdeck large image | 2 // @name Tweetdeck large image |
| 3 // @namespace https://myconan.net | 3 // @namespace https://myconan.net |
| 4 // @version 2.0.2 | 4 // @version 2.0.3 |
| 5 // @description No more stupid link for images in tweetdeck | 5 // @description No more stupid link for images in tweetdeck |
| 6 // @author nanaya | 6 // @author nanaya |
| 7 // @match https://tweetdeck.twitter.com/* | 7 // @match https://tweetdeck.twitter.com/* |
| 8 // @grant none | 8 // @grant none |
| 9 // @downloadURL https://bitbucket.org/nanayapro/ec-userscripts/raw/tip/tweetdeck-large-image.user.js | 9 // @downloadURL https://bitbucket.org/nanayapro/ec-userscripts/raw/tip/tweetdeck-large-image.user.js |
| 44 link._ecUserscript = true; | 44 link._ecUserscript = true; |
| 45 | 45 |
| 46 var image = link.querySelector(".media-img"); | 46 var image = link.querySelector(".media-img"); |
| 47 var url; | 47 var url; |
| 48 | 48 |
| 49 // sometimes the image is just background image of the link. | |
| 50 // strip all query strings and original :size suffix | |
| 49 if (image == null) { | 51 if (image == null) { |
| 50 // sometimes the image is just background image of the link. | 52 |
| 51 // strip all query strings and original :size suffix | 53 var linkStyle = getComputedStyle(link); |
| 52 url = getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)(?::small)?(?:\?.*)?\1\)$/, "$2"); | 54 |
| 55 if (linkStyle == null) { | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 url = linkStyle.backgroundImage.replace(/^url\(('|")?(.+?)(?::small)?(?:\?.*)?\1\)$/, "$2"); | |
| 53 } else { | 60 } else { |
| 54 url = image.src.replace(/:[a-z0-9]+(?:\?.*)?$/, ""); | 61 url = image.src.replace(/:[a-z0-9]+(?:\?.*)?$/, ""); |
| 55 } | 62 } |
| 56 | 63 |
| 57 link.setAttribute("href", url + ":orig"); | 64 link.setAttribute("href", url + ":orig"); |
