diff tweetdeck-large-image.user.js @ 63:53d0f935ecb8

Fix orig might be in different format
author nanaya <me@nanaya.pro>
date Wed, 10 Jul 2019 22:26:12 +0900
parents a065dafbe010
children 6715e53ad0bf
line wrap: on
line diff
--- a/tweetdeck-large-image.user.js	Wed Jul 10 11:29:08 2019 +0900
+++ b/tweetdeck-large-image.user.js	Wed Jul 10 22:26:12 2019 +0900
@@ -1,7 +1,7 @@
 // ==UserScript==
 // @name         Tweetdeck large image
 // @namespace    https://myconan.net
-// @version      2.0.4
+// @version      2.0.5
 // @description  No more stupid link for images in tweetdeck
 // @author       nanaya
 // @match        https://tweetdeck.twitter.com/*
@@ -54,10 +54,14 @@
       url = image.src;
     }
 
-    if (url.match(/\..+:.+/) != null) {
+    parsedUrl = new URL(url);
+
+    if (parsedUrl.searchParams.get('name') == null) {
       url = url.replace(/(\..+:).+/, "$1orig");
-    } else if (url.match(/name=/) != null) {
-      url = url.replace(/(\?|&)name=.+($|&)/, "$1name=orig$2");
+    } else {
+      parsedUrl.searchParams.delete('format');
+      parsedUrl.searchParams.set('name', 'orig');
+      url = parsedUrl.href;
     }
 
     link.setAttribute("href", url);