Extension to return old Twitter layout from 2015.
1let xi = setInterval(() => {
2 let xIcon = document.querySelector('a[href^="https://twitter.com/home"] > div > svg');
3 if(xIcon) {
4 let parent = xIcon.parentElement;
5 let img = document.createElement('img');
6 img.src = chrome.runtime.getURL('images/logo32_new.png');
7 img.style.cssText = 'width: 2em;height: 2em;image-rendering: -webkit-optimize-contrast;filter: brightness(99);';
8 parent.appendChild(img);
9 xIcon.remove();
10 clearInterval(xi);
11 };
12});
13
14function removeAndReplaceX(element) {
15 if(element) {
16 let parent = element.parentElement;
17 let img = document.createElement('img');
18 img.src = chrome.runtime.getURL('images/logo32_new.png');
19 img.style.cssText = 'width: 2em;height: 2em;image-rendering: -webkit-optimize-contrast;filter: brightness(99);display: block;top: 50%;position: absolute;left: 50%;transform: translate(-50%, -50%);';
20 parent.appendChild(img);
21 element.remove();
22 xObserver.disconnect();
23
24 setTimeout(() => {
25 img.remove();
26 }, 500);
27 };
28}
29
30const xObserver = new MutationObserver((mutations) => {
31 mutations.forEach((mutation) => {
32 if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
33 mutation.addedNodes.forEach((node) => {
34 if (node.nodeType === Node.ELEMENT_NODE) {
35 if(node.tagName === 'SVG') {
36 removeAndReplaceX(node);
37 }
38 node.querySelectorAll('svg').forEach(removeAndReplaceX);
39 }
40 });
41 }
42 });
43});
44
45// Start observing the page for changes
46xObserver.observe(document.documentElement, { childList: true, subtree: true });