Skip to content

Commit

Permalink
Remove outdated palette button hiding code (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Apr 29, 2024
1 parent 18d9fe1 commit 1806efb
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
const delayToDocumentIdle = delayedFunction => {
document.readyState === 'complete'
? delayedFunction()
: window.addEventListener('load', delayedFunction);
};

const hideChangePaletteButton = function () {
if (document.getElementById('palette-override') !== null) {
return;
}

if ([...document.scripts].some(({ src }) => src.includes('/pop/')) === false) {
return;
}

const toRunInPageContext = function () {
const changePaletteLabel = window.tumblr.languageData.translations['Change Palette'] || 'Change Palette';
const textContent = `button[aria-label="${changePaletteLabel}"] { display: none !important; }`;
const style = Object.assign(document.createElement('style'), { textContent, id: 'palette-override' });
document.head.append(style);
};

const scriptWithNonce = [...document.scripts].find(script => script.getAttributeNames().includes('nonce'));
const nonce = scriptWithNonce.nonce || scriptWithNonce.getAttribute('nonce');

const injectable = `(${toRunInPageContext.toString()})()`;
const script = Object.assign(document.createElement('script'), { nonce, textContent: injectable });
document.documentElement.append(script);
script.remove();
};

const showChangePaletteButton = function () {
const style = document.getElementById('palette-override');
if (style) style.remove();
Expand All @@ -50,8 +19,6 @@ const applyCurrentPalette = async function () {
return;
}

delayToDocumentIdle(hideChangePaletteButton);

const paletteIsBuiltIn = currentPalette.startsWith('palette:') === false;
const { [currentPalette]: currentPaletteData = {} } = paletteIsBuiltIn
? await paletteData
Expand Down

0 comments on commit 1806efb

Please sign in to comment.