Created
June 9, 2022 02:53
-
-
Save q00u/2fc01cecc3969b669ba3e490a60d840d to your computer and use it in GitHub Desktop.
This file contains 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 *Scans Link Decolorer | |
// @namespace https://gist.github.com/q00u | |
// @version 0.3 | |
// @description Realmscans/Luminousscans makes all links (visited or not) the same color. This undoes that. | |
// @author Phoenix G | |
// @match https://realmscans.com/* | |
// @match https://luminousscans.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=realmscans.com | |
// @run-at document-idle | |
// @grant none | |
// ==/UserScript== | |
(async function() { | |
"use string"; | |
const delay = ms => new Promise(res => setTimeout(res, ms)); | |
const debugging = true; | |
if (true) { // Just to scope variables | |
let externalFound = false; | |
if (debugging) console.log('Processing stylesheets looking for external sheets'); | |
const oldSheets = Array.from(document.styleSheets); | |
for (const [i, oldSheet] of oldSheets.entries()) { | |
if (oldSheet.href && !oldSheet.href.startsWith(window.location.origin)) { | |
if (debugging) console.log('Found external stylesheet, processing...'); | |
externalFound = true; | |
// Sheet loaded from external file, rules will be inaccessible | |
const newLink = document.createElement('link'); | |
newLink.rel = 'stylesheet'; | |
newLink.type = 'text/css'; | |
newLink.crossOrigin = 'anonymous'; | |
newLink.href = oldSheet.href; | |
document.getElementsByTagName('HEAD')[0].appendChild(newLink); | |
oldSheet.disabled = true; | |
} | |
} | |
if (externalFound) await delay(50); // Wait for CSS to update | |
} | |
if (debugging) console.log('Beginning search for .chapternum'); | |
let sheetRefs = Array.from(document.styleSheets); | |
for (const [j, sheetRef] of sheetRefs.entries()) { | |
const srsl = sheetRefs.length; | |
// Check to see if this sheet is external | |
let sl = null; | |
try {sl = sheetRef?.rules?.length;} catch(e) {} | |
if (debugging) console.log(`Checking sheet ${j}/${srsl - 1}, ${sl} rules`); | |
if (sl) { | |
for (let i = 0; i < sl; i++) { | |
if (sheetRef.rules[i].selectorText==".chapternum") { | |
console.log('Found and removing .chapternum'); | |
sheetRef.removeRule(i) | |
} | |
} | |
} | |
} | |
if (debugging) console.log('Finished search for .chapternum'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment