Skip to content

Commit

Permalink
feat: support changing navbar icon
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed Jul 25, 2023
1 parent 1545277 commit 19cab37
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions script.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,43 @@
});
});

const LOGO_SELECTOR = 'a[href="/home"][aria-label="Twitter"]';
const NAVBAR_LOGO_SELECTOR =
'div[data-testid="TopNavBar"] > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)';
const PLACEHOLDER_SELECTOR = "#placeholder";

/** @param {boolean} show */
const makeTwitterLogoStyle = (show) =>
`a[href="/home"][aria-label="Twitter"] { display: ${
show ? "flex" : "block"
}; }`;
`${LOGO_SELECTOR} { display: ${show ? "flex" : "block"}; }`;

/** @param {boolean} show */
const makeTwitterNavbarLogoStyle = (show) =>
`${NAVBAR_LOGO_SELECTOR} { display: ${show ? "flex" : "block"}; }`;

/** @param {boolean} show */
const makePlaceholderStyle = (show) =>
`#placeholder { display: ${show ? "flex" : "none"}; }`;
`${PLACEHOLDER_SELECTOR} { display: ${show ? "flex" : "none"}; }`;

GM_addStyle(makeTwitterLogoStyle(false));
GM_addStyle(makeTwitterNavbarLogoStyle(false));
GM_addStyle(makePlaceholderStyle(false));
GM_addStyle(COLOR_CSS);

const iconElement = document.querySelector('link[rel="shortcut icon"]');
iconElement.href = TWITTER_LOGO_FOR_SHORTCUT_ICON;

waitForElement("#placeholder").then((placeholder) => {
waitForElement(PLACEHOLDER_SELECTOR).then((placeholder) => {
placeholder.children[0].innerHTML = TWITTER_LOGO;
GM_addStyle(makePlaceholderStyle(true));
});

waitForElement('a[href="/home"][aria-label="Twitter"]').then((a) => {
waitForElement(LOGO_SELECTOR).then((a) => {
a.children[0].innerHTML = TWITTER_LOGO;
GM_addStyle(makeTwitterLogoStyle(true));
});

waitForElement(NAVBAR_LOGO_SELECTOR).then((div) => {
div.innerHTML = TWITTER_LOGO;
GM_addStyle(makeTwitterNavbarLogoStyle(true));
});
})();

0 comments on commit 19cab37

Please sign in to comment.