Created
May 16, 2021 20:54
-
-
Save Fuyukai/16a72967f5deef1f3d36f3737ef4e1b5 to your computer and use it in GitHub Desktop.
Userscript that disables custom CSS on the SCP Wiki.
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 Delete Custom SCP CSS | |
// @match *://scp-wiki.wikidot.com/* | |
// @match *://www.scpwiki.com/* | |
// @grant none | |
// @version 1.0 | |
// @author Lura Skye | |
// @description Disables custom SCP CSS. Has special handling for a few variants. | |
// @run_at document-end | |
// @homepage_url https://gist.github.com/Fuyukai/16a72967f5deef1f3d36f3737ef4e1b5 | |
// ==/UserScript== | |
// Step 1: Strip off any anonymous style tags. | |
const styles = document.head.querySelectorAll("style"); | |
styles.forEach((it) => { | |
if (it.attributes.length === 0) { | |
it.remove(); | |
} | |
}); | |
function add_to_page_body(item_number, containment_class) { | |
const page_body = document.body.querySelector("#main-content"); | |
const actual_body = page_body.querySelector("#page-content"); | |
const first_paragraph = actual_body.querySelector(":scope > p"); | |
const inserted_number = actual_body.insertBefore((function() { | |
const elem = document.createElement("p"); | |
elem.id = "_item-number" | |
elem.innerHTML = "<strong>Item #:</strong> " + item_number; | |
return elem; | |
})(), first_paragraph); | |
const obclass = actual_body.insertBefore((function() { | |
const elem = document.createElement("p"); | |
elem.setAttribute("style", "text-transform:capitalize") | |
elem.innerHTML = "<strong>Object Class:</strong> " + containment_class; | |
return elem; | |
})(), inserted_number.nextSibling); | |
} | |
// Variant 1 tweaks. | |
// | |
// Delete the credit box clutter at the top. | |
const variant1 = document.body.querySelector("#u-credit-view"); | |
if (variant1 !== null) { | |
variant1.remove(); | |
const anom_bar = document.body.querySelector(".anom-bar"); | |
if (anom_bar !== null) { | |
const item_number = anom_bar.querySelector("span.number").textContent; | |
const containment_class = anom_bar.querySelector(".contain-class").querySelector(".class-text").textContent; | |
add_to_page_body(item_number, containment_class); | |
// now we've copied all we need into the body we simply murder the bar | |
anom_bar.remove(); | |
} | |
// finally, fix the rate box and remove the big gap at the top | |
const credit_rate = document.body.querySelector(".creditRate"); | |
credit_rate.parentNode.nextElementSibling.nextSibling.remove(); | |
credit_rate.parentNode.nextElementSibling.remove(); | |
const rate_box = credit_rate.querySelector(".rate-box-with-credit-button"); | |
rate_box.className = ""; | |
rate_box.setAttribute("style", "text-align:right"); | |
rate_box.querySelector(".creditButton").remove(); | |
} | |
// Variant 2 tweaks. | |
// | |
// Delete the class1 stuff. | |
const variant2 = document.body.querySelector(".class1image"); | |
if (variant2 !== null) { | |
variant2.remove(); | |
const header = document.body.querySelector(".class1").parentNode; | |
const author_block = document.body.querySelector(".info-container"); | |
if (author_block !== null) author_block.remove(); | |
const item_num = document.body.querySelector(".itemnum").innerText.split(": ")[1]; | |
const object_class = document.body.querySelector(".objclass .obj .obj-text").innerText; | |
add_to_page_body(item_num, object_class); | |
header.remove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment