TwitterSHB

Twitter Slim Home Bar

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         TwitterSHB
// @namespace    https://rinrin.me/
// @version      0.2
// @description  Twitter Slim Home Bar
// @author       rin4046
// @match        https://twitter.com/*
// @grant        none
// @license MIT
// ==/UserScript==

{
    const getElementByXPath = (parent, xpath) => {
        return document.evaluate(xpath, parent, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    };

    const observer = new MutationObserver((muataions, observer) => {
        const wrapper = getElementByXPath(document, "/html/body/div[1]/div/div/div[2]/main/div/div/div/div[1]/div/div[1]/div[1]");

        if (wrapper && window.location.pathname === "/home") {
            const top = wrapper.children[0];
            const bottom = wrapper.children[1];

            const tab = getElementByXPath(wrapper, "div[2]/nav/div/div[2]/div");
            if (!tab.getAttribute("swapped") && tab.children[0].children[0].nodeName === "A") {
                tab.appendChild(tab.children[0]);
                tab.children[0].children[0].click();
                tab.setAttribute("swapped", true);
            }

            wrapper.style.flexDirection = "row";
            bottom.style.flexGrow = 1;

            const { borderBottomWidth, borderBottomStyle, borderBottomColor } = window.getComputedStyle(bottom.children[0]);
            top.style.borderBottomWidth = borderBottomWidth;
            top.style.borderBottomStyle = borderBottomStyle;
            top.style.borderBottomColor = borderBottomColor;
        }
    });
    observer.observe(document.body, { childList: true, subtree: true });
}