comparison tweetdeck-fixes.user.js @ 110:b9b84779a672

Combine tweetdeck fixes
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:36:45 +0900
parents tweetdeck-large-image.user.js@ef21ef445fc6
children 055f5d084706
comparison
equal deleted inserted replaced
109:ef21ef445fc6 110:b9b84779a672
1 // ==UserScript==
2 // @name Tweetdeck large image
3 // @namespace https://nanaya.net
4 // @version 2.0.9
5 // @description Fixes for TweetDeck
6 // @author nanaya
7 // @match https://tweetdeck.twitter.com/*
8 // @grant none
9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/tweetdeck-fixes.user.js
10 // ==/UserScript==
11
12 'use strict';
13
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
33 function origLink () {
34 const fix = function (link) {
35 // basic sanity check
36 if (!link.classList.contains('js-media-image-link')) {
37 return;
38 }
39
40 // don't run again if already run on passed link
41 if (link._ecUserscript) {
42 return;
43 }
44 link._ecUserscript = true;
45
46 const image = link.querySelector('.media-img');
47 let url;
48
49 // sometimes the image is just background image of the link.
50 // strip all query strings and original :size suffix
51 if (image == null) {
52 url = window.getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)\1\)$/, '$2');
53 } else {
54 url = image.src;
55 }
56
57 const parsedUrl = new URL(url);
58
59 if (parsedUrl.searchParams.get('name') == null) {
60 url = url.replace(/(\..+:).+/, '$1orig');
61 } else {
62 if (parsedUrl.pathname.match(/\.[^.]+$/) !== null) {
63 parsedUrl.searchParams.delete('format');
64 }
65 parsedUrl.searchParams.set('name', 'orig');
66 url = parsedUrl.href;
67 }
68
69 link.setAttribute('href', url);
70 };
71
72 // loop through passed nodes (or body if called without arguments)
73 const run = function (nodes) {
74 if (nodes == null) {
75 nodes = [document.body];
76 }
77
78 for (let i = 0; i < nodes.length; i++) {
79 // first try fixing itself
80 fix(nodes[i]);
81
82 // and then find all the links inside
83 const links = nodes[i].querySelectorAll('.js-media-image-link');
84
85 for (let j = 0; j < links.length; j++) {
86 fix(links[j]);
87 }
88 }
89 };
90
91 const onMutate = function (mutations) {
92 for (const mutation in mutations) {
93 run(mutation.addedNodes);
94 }
95 };
96
97 // the observer
98 const observer = new window.MutationObserver(onMutate);
99
100 // start the observer
101 observer.observe(document, { childList: true, subtree: true });
102 // initial run on existing document
103 run();
104 }
105
106 fixColumn();
107 origLink();