comparison tweetdeck-large-image.user.js @ 60:cd3ffdc31613

Better null check
author nanaya <me@nanaya.pro>
date Sun, 05 May 2019 22:36:10 +0900
parents 960d452dea99
children 753765f3814e
comparison
equal deleted inserted replaced
59:3381a9cb88d1 60:cd3ffdc31613
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.1 4 // @version 2.0.2
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
12 ;(function() { 12 ;(function() {
13 "use strict"; 13 "use strict";
14 14
15 // loop through passed nodes (or body if called without arguments) 15 // loop through passed nodes (or body if called without arguments)
16 var run = function(nodes) { 16 var run = function(nodes) {
17 if (nodes === undefined) { 17 if (nodes == null) {
18 nodes = [document.body]; 18 nodes = [document.body];
19 } 19 }
20 20
21 for (var i = 0; i < nodes.length; i++) { 21 for (var i = 0; i < nodes.length; i++) {
22 // first try fixing itself 22 // first try fixing itself
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 if (image === null) { 49 if (image == null) {
50 // sometimes the image is just background image of the link. 50 // sometimes the image is just background image of the link.
51 // strip all query strings and original :size suffix 51 // strip all query strings and original :size suffix
52 url = getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)(?::small)?(?:\?.*)?\1\)$/, "$2"); 52 url = getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)(?::small)?(?:\?.*)?\1\)$/, "$2");
53 } else { 53 } else {
54 url = image.src.replace(/:[a-z0-9]+(?:\?.*)?$/, ""); 54 url = image.src.replace(/:[a-z0-9]+(?:\?.*)?$/, "");