Mercurial > ec-userscripts
annotate tweetdeck-fixes.user.js @ 114:817b62848b27
Backed out changeset 055f5d084706
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 15 Jan 2023 23:43:40 +0900 |
parents | 647ade033475 |
children |
rev | line source |
---|---|
24 | 1 // ==UserScript== |
114 | 2 // @name Tweetdeck large image |
109 | 3 // @namespace https://nanaya.net |
114 | 4 // @version 2.0.9 |
110 | 5 // @description Fixes for TweetDeck |
24 | 6 // @author nanaya |
7 // @match https://tweetdeck.twitter.com/* | |
113 | 8 // @grant none |
110 | 9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/tweetdeck-fixes.user.js |
24 | 10 // ==/UserScript== |
11 | |
109 | 12 'use strict'; |
33 | 13 |
110 | 14 /* global GM_addStyle */ |
15 // No weird column alignment and color for scrollbar | |
16 function fixColumn () { | |
17 GM_addStyle(` | |
18 .app-columns { | |
19 display: flex; | |
20 } | |
21 .column { | |
22 top: 0; | |
23 flex: none; | |
24 } | |
25 .app-columns-container.app-columns-container.app-columns-container.app-columns-container { | |
26 bottom: 0; | |
27 background-color: #555; | |
28 } | |
29 `); | |
30 } | |
31 | |
32 // No more stupid link for images in tweetdeck | |
109 | 33 function origLink () { |
85 | 34 const fix = function (link) { |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
35 // basic sanity check |
66 | 36 if (!link.classList.contains('js-media-image-link')) { |
108 | 37 return; |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
38 } |
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
39 |
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
40 // don't run again if already run on passed link |
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
41 if (link._ecUserscript) { |
108 | 42 return; |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
43 } |
108 | 44 link._ecUserscript = true; |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
45 |
108 | 46 const image = link.querySelector('.media-img'); |
47 let url; | |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
48 |
61
753765f3814e
Not sure why but sometimes link style is null?
nanaya <me@nanaya.pro>
parents:
60
diff
changeset
|
49 // sometimes the image is just background image of the link. |
753765f3814e
Not sure why but sometimes link style is null?
nanaya <me@nanaya.pro>
parents:
60
diff
changeset
|
50 // strip all query strings and original :size suffix |
60 | 51 if (image == null) { |
108 | 52 url = window.getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)\1\)$/, '$2'); |
28 | 53 } else { |
108 | 54 url = image.src; |
28 | 55 } |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
56 |
108 | 57 const parsedUrl = new URL(url); |
63
53d0f935ecb8
Fix orig might be in different format
nanaya <me@nanaya.pro>
parents:
62
diff
changeset
|
58 |
53d0f935ecb8
Fix orig might be in different format
nanaya <me@nanaya.pro>
parents:
62
diff
changeset
|
59 if (parsedUrl.searchParams.get('name') == null) { |
108 | 60 url = url.replace(/(\..+:).+/, '$1orig'); |
63
53d0f935ecb8
Fix orig might be in different format
nanaya <me@nanaya.pro>
parents:
62
diff
changeset
|
61 } else { |
67
f03e2d169a8a
Only delete format if there's extension in filename
nanaya <me@nanaya.pro>
parents:
66
diff
changeset
|
62 if (parsedUrl.pathname.match(/\.[^.]+$/) !== null) { |
108 | 63 parsedUrl.searchParams.delete('format'); |
67
f03e2d169a8a
Only delete format if there's extension in filename
nanaya <me@nanaya.pro>
parents:
66
diff
changeset
|
64 } |
108 | 65 parsedUrl.searchParams.set('name', 'orig'); |
66 url = parsedUrl.href; | |
62
a065dafbe010
Update to handle new tweetdeck?/twitter? url
nanaya <me@nanaya.pro>
parents:
61
diff
changeset
|
67 } |
a065dafbe010
Update to handle new tweetdeck?/twitter? url
nanaya <me@nanaya.pro>
parents:
61
diff
changeset
|
68 |
108 | 69 link.setAttribute('href', url); |
70 }; | |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
71 |
85 | 72 // loop through passed nodes (or body if called without arguments) |
73 const run = function (nodes) { | |
74 if (nodes == null) { | |
108 | 75 nodes = [document.body]; |
85 | 76 } |
77 | |
78 for (let i = 0; i < nodes.length; i++) { | |
79 // first try fixing itself | |
108 | 80 fix(nodes[i]); |
85 | 81 |
82 // and then find all the links inside | |
108 | 83 const links = nodes[i].querySelectorAll('.js-media-image-link'); |
85 | 84 |
85 for (let j = 0; j < links.length; j++) { | |
108 | 86 fix(links[j]); |
85 | 87 } |
88 } | |
108 | 89 }; |
85 | 90 |
91 const onMutate = function (mutations) { | |
92 for (const mutation in mutations) { | |
108 | 93 run(mutation.addedNodes); |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
94 } |
108 | 95 }; |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
96 |
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
97 // the observer |
108 | 98 const observer = new window.MutationObserver(onMutate); |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
99 |
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
100 // start the observer |
108 | 101 observer.observe(document, { childList: true, subtree: true }); |
55
19c391840d4a
Rewrite the whole thing to use observer instead
nanaya <me@nanaya.pro>
parents:
49
diff
changeset
|
102 // initial run on existing document |
108 | 103 run(); |
109 | 104 } |
105 | |
110 | 106 fixColumn(); |
109 | 107 origLink(); |