Last active
February 3, 2025 10:06
-
-
Save Soochaehwa/5179594a768d91dae9270dc130c4bff6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Fuck Powerlink | |
// @namespace Violentmonkey Scripts | |
// @match https://namu.wiki/w/* | |
// @version 1.5 | |
// @updateURL https://gist.github.com/Soochaehwa/5179594a768d91dae9270dc130c4bff6/raw/Fuck_Powerlink.user.js | |
// @downloadURL https://gist.github.com/Soochaehwa/5179594a768d91dae9270dc130c4bff6/raw/Fuck_Powerlink.user.js | |
// @grant unsafeWindow | |
// @run-at document-start | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const getTargetColor = () => { | |
const getSeedTheme = () => { | |
try { | |
const settings = JSON.parse(localStorage.getItem('theseed_settings') || '{}'); | |
return settings['wiki.theme'] || null; | |
} catch { | |
return null; | |
} | |
}; | |
const seedTheme = getSeedTheme(); | |
if (seedTheme === 'dark') return 'rgb(43, 43, 43)'; | |
if (seedTheme === 'light') return 'rgb(255, 254, 249)'; | |
return window.matchMedia('(prefers-color-scheme: dark)').matches | |
? 'rgb(43, 43, 43)' | |
: 'rgb(255, 254, 249)'; | |
}; | |
let lastThemeState = null; | |
const getCachedTargetColor = () => { | |
const currentColor = getTargetColor(); | |
if (currentColor !== lastThemeState) { | |
lastThemeState = currentColor; | |
} | |
return currentColor; | |
}; | |
const removeBackgroundElements = () => { | |
console.log('removeBackgroundElements'); | |
const targetColor = getCachedTargetColor(); | |
const elements = document.getElementsByTagName('*'); | |
for (let i = elements.length - 1; i >= 0; i--) { | |
const element = elements[i]; | |
const bgColor = window.getComputedStyle(element).backgroundColor; | |
if (bgColor === targetColor) { | |
const parent = element.parentElement; | |
if (parent && parent.children.length === 6) { | |
const grandParent = parent.parentElement; | |
grandParent && grandParent.remove(); | |
} else { | |
element.remove(); | |
} | |
break; | |
} | |
} | |
}; | |
const initObserver = () => { | |
const observer = new MutationObserver(removeBackgroundElements); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true, | |
}); | |
}; | |
if (document.readyState === 'loading') { | |
document.addEventListener('DOMContentLoaded', () => { | |
initObserver(); | |
}); | |
} else { | |
initObserver(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment