comparison tweetdeck-large-image.user.js @ 62:a065dafbe010

Update to handle new tweetdeck?/twitter? url
author nanaya <me@nanaya.pro>
date Wed, 10 Jul 2019 11:29:08 +0900
parents 753765f3814e
children 53d0f935ecb8
comparison
equal deleted inserted replaced
61:753765f3814e 62:a065dafbe010
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.3 4 // @version 2.0.4
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
47 var url; 47 var url;
48 48
49 // sometimes the image is just background image of the link. 49 // sometimes the image is just background image of the link.
50 // strip all query strings and original :size suffix 50 // strip all query strings and original :size suffix
51 if (image == null) { 51 if (image == null) {
52 52 url = getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)\1\)$/, "$2");
53 var linkStyle = getComputedStyle(link);
54
55 if (linkStyle == null) {
56 return;
57 }
58
59 url = linkStyle.backgroundImage.replace(/^url\(('|")?(.+?)(?::small)?(?:\?.*)?\1\)$/, "$2");
60 } else { 53 } else {
61 url = image.src.replace(/:[a-z0-9]+(?:\?.*)?$/, ""); 54 url = image.src;
62 } 55 }
63 56
64 link.setAttribute("href", url + ":orig"); 57 if (url.match(/\..+:.+/) != null) {
58 url = url.replace(/(\..+:).+/, "$1orig");
59 } else if (url.match(/name=/) != null) {
60 url = url.replace(/(\?|&)name=.+($|&)/, "$1name=orig$2");
61 }
62
63 link.setAttribute("href", url);
65 64
66 }; 65 };
67 66
68 var onMutate = function(mutations) { 67 var onMutate = function(mutations) {
69 for (var mutation in mutations) { 68 for (var mutation in mutations) {