|
6 | 6 | // @match https://piaille.fr/* |
7 | 7 | // @match https://eldritch.cafe/* |
8 | 8 | // @match https://h-i.social/* |
| 9 | +// @match https://diaspodon.fr/* |
9 | 10 | // @match https://AddYourInstanceUrlHere.tld/* |
10 | 11 | // @downloadURL https://github.com/Write/TangerineUI-Userscript/raw/main/TangerineUI.user.js |
11 | 12 | // @updateURL https://github.com/Write/TangerineUI-Userscript/raw/main/TangerineUI.user.js |
12 | 13 | // @homepageURL https://github.com/Write/TangerineUI-Userscript |
13 | 14 | // @grant none |
14 | | -// @version 2.2.3 |
| 15 | +// @version 2.2.3.1 |
15 | 16 | // @author @Write on Github for the UserScript |
16 | 17 | // @author @nileane for TangerineUI's CSS |
17 | 18 | // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACE0lEQVR4AZXOA2xeUQAF4BvNW8xGi7WFY227v81otu0Fs23btq3attunvrN7//bOPMmX98414bFa4edyda12u7te0m8d1UKhRyNVT32idrtcGE6+jdMpBzjtUjOFf2KTZJddchKWsWPR22HprKLATBwnYOM6CfNni+Bjs2d0j02ZKLDOCVZrhx9xGNuT7aY2MAvmdKCjQwXP0UMidm4ToPYMiSKwcmkn+Hqbsd1L7LqWqTZ9M5injyXf4oN7O3HkQCdkGRAEFWdOCNi9vROKAnx8L4Ovt+uaZhCbpn6eTVsPpjBfRkN9F3ivLFfQ0qJ+6SXFCupqv86zvcSWVjPTml4DprhQRm21At7ZgbU1X3tBnoxGegHvlvSa2cSaUjXWklIJhh/Ae2Ge5DuA94JcyfdC3q2plVOJObncYU4qA1NcIPkO4H2soxLjXZW80wNEesDXeVNSqYcY44s1pvhiMDcvt+LB7Tbw/qPrF1rx+F77l25IKh1KjNEFw40xBfhfhpiCs4RFE/JxgDEqR6Xwj5qptZaot/0JjyE867UhPBOcMeJThCH8U6QhLNNgjMj06iMyjfQ/0RSROSQ2Nrc3+TG60I/J+tAPKgWfsI/7NaMe9SXfxBSbO4j8Kdrgdx5d0FuBQrd3zbrgN28Y2quofPK3aILeDtb6v1yt8X/5Suv/qo0Sdf6vijT+r05q/F9Hkl/kM/y+SpUd6mHfAAAAAElFTkSuQmCC |
|
31 | 32 |
|
32 | 33 | /* colorScheme used for new (>= 4.3) instances */ |
33 | 34 | /* Either 'tangerine', 'purple', 'cherry' or 'lagoon' */ |
34 | | - const colorScheme = 'tangerine'; |
| 35 | + const colorScheme = 'cherry'; |
35 | 36 |
|
36 | 37 | /* Github tag to use for mastodon instance < 4.3 and >= 4.3 |
37 | 38 | /* To find tags name, go here : https://github.com/nileane/TangerineUI-for-Mastodon/releases |
|
98 | 99 | let isVersionDetected = false; |
99 | 100 | let nonce; |
100 | 101 |
|
| 102 | + function isVersionAtLeast(version, minVersion) { |
| 103 | + const parseVersion = (v) => v.split('.').map(num => parseInt(num, 10)); |
| 104 | + const current = parseVersion(version); |
| 105 | + const minimum = parseVersion(minVersion); |
| 106 | + |
| 107 | + for (let i = 0; i < Math.max(current.length, minimum.length); i++) { |
| 108 | + const currentPart = current[i] || 0; |
| 109 | + const minimumPart = minimum[i] || 0; |
| 110 | + |
| 111 | + if (currentPart > minimumPart) return true; |
| 112 | + if (currentPart < minimumPart) return false; |
| 113 | + } |
| 114 | + return true; // Equal versions |
| 115 | + } |
| 116 | + |
101 | 117 | /* Version detection */ |
102 | 118 | onElemAvailable('script[id^=initial-state]').then((selector) => { |
103 | 119 | isVersionDetected = true; |
104 | 120 | const mastodonVersion = JSON.parse(selector.innerText).meta.version |
105 | 121 | log("Mastodon Version Detected is : " + mastodonVersion); |
106 | | - if (mastodonVersion.includes('4.3.') || mastodonVersion.includes('4.4.') || mastodonVersion.includes('4.5.')) { |
| 122 | + if (isVersionAtLeast(mastodonVersion, '4.3.0')) { |
107 | 123 | log("Version above or equal 4.3.0 found.") |
108 | 124 | if (isPurple) |
109 | 125 | styleUrl = tangerine_above_or_equals_4_3_0 + "-purple.min.css" |
|
170 | 186 | isVersionDetected = true; |
171 | 187 | const mastodonVersion = JSON.parse(node.innerText).meta.version |
172 | 188 | log("(mutationObserver) Mastodon Version Detected is : " + mastodonVersion); |
173 | | - if (mastodonVersion.includes('4.3.') || mastodonVersion.includes('4.4.') || mastodonVersion.includes('4.5.')) { |
| 189 | + if (isVersionAtLeast(mastodonVersion, '4.3.0')) { |
174 | 190 | log("(mutationObserver) Version above or equal 4.3.0 found.") |
175 | 191 | if (isPurple) |
176 | 192 | styleUrl = tangerine_above_or_equals_4_3_0 + "-purple.min.css" |
|
190 | 206 | href = node.href; |
191 | 207 | const rChunk = /\/packs\/css\/mastodon.*\.chunk\.css/ |
192 | 208 | const rCustom = /custom\.css/ |
193 | | - |
194 | | - /* Inject after custom.css or mastodon.*.chunk.css, whichever is detected first |
195 | | - * On my system mastodon.*.chunk.css wasn't detected on Chrome |
196 | | - * */ |
197 | | - if ((href.match(rCustom) || href.match(rChunk)) && !isInjected) { |
| 209 | + const rCustomWithHash = /custom-[a-f0-9]+\.css/ |
| 210 | + /* Inject after custom.css (old or new format) or mastodon.*.chunk.css, whichever is detected first |
| 211 | + * On my system mastodon.*.chunk.css wasn't detected on Chrome |
| 212 | + */ |
| 213 | + if ((href.match(rCustom) || href.match(rCustomWithHash) || href.match(rChunk)) && !isInjected) { |
198 | 214 | if (nonce && isVersionDetected) { |
199 | 215 | nChanges++; |
200 | 216 | isInjected = true; |
|
248 | 264 | /* Workaround if MutationObserver couldn't detect the item |
249 | 265 | * Usually in Safari and Chrome (for Chrome, the first load seems to use MutationObserver, but anyway) |
250 | 266 | * */ |
251 | | - onElemAvailable('link[rel^=stylesheet][href*=custom\\.css]').then(() => { |
252 | | - if (!isInjected) { |
253 | | - if (nonce) { |
254 | | - document.head.appendChild(createStyleNode(nonce)); |
255 | | - isInjected = true; |
256 | | - log("(requestAnimationFrame) custom.css detected, injected TangerineUI's css asap"); |
257 | | - } |
258 | | - else { |
259 | | - isInjected = true; |
260 | | - onElemAvailable('meta[name^=style\\-nonce]').then((selector) => { |
261 | | - let nonce_fallback = selector.content; |
262 | | - document.head.appendChild(createStyleNode(nonce_fallback)); |
263 | | - log("Nonce was lookedup with requestAnimationFrame as MutationObserver didn't catch it."); |
264 | | - log('Nonce found is ' + nonce_fallback); |
| 267 | + onElemAvailable('link[rel="stylesheet"][href*="custom"]').then((elem) => { |
| 268 | + if (elem.href.includes('custom.css') || elem.href.match(/custom-[a-f0-9]+\.css/)) { |
| 269 | + if (!isInjected) { |
| 270 | + if (nonce) { |
| 271 | + document.head.appendChild(createStyleNode(nonce)); |
| 272 | + isInjected = true; |
265 | 273 | log("(requestAnimationFrame) custom.css detected, injected TangerineUI's css asap"); |
266 | | - }); |
| 274 | + } |
| 275 | + else { |
| 276 | + isInjected = true; |
| 277 | + onElemAvailable('meta[name^=style\\-nonce]').then((selector) => { |
| 278 | + let nonce_fallback = selector.content; |
| 279 | + document.head.appendChild(createStyleNode(nonce_fallback)); |
| 280 | + log("Nonce was lookedup with requestAnimationFrame as MutationObserver didn't catch it."); |
| 281 | + log('Nonce found is ' + nonce_fallback); |
| 282 | + log("(requestAnimationFrame) custom.css detected, injected TangerineUI's css asap"); |
| 283 | + }); |
| 284 | + } |
267 | 285 | } |
268 | 286 | } |
269 | 287 | }); |
|
0 commit comments