// ==UserScript== // @name block fucking harry potter // @description removes harry potter listings on fanfiction.net // @namespace chad // @include https://www.fanfiction.net/* // @version 1 // @grant none // @downloadURL none // ==/UserScript== const blocked = ["Harry Potter"] function exit(message="Script Completed") { throw new Error(message) } function isNumeric(value) { return /^-?\d+$/.test(value); } let listingElements = document.getElementsByClassName("z-list") // not on crossover or search page if (!(listingElements.length > 0 && window.location.href.split("/")[3] != "u" && (isNumeric(window.location.href.split("/")[5]) || window.location.href.split("/")[3] == "search") )) { exit() } function addCSS(css='') { style = document.createElement('style') document.head.append(style) style.textContent = css return style } class Listing { constructor(element) { this.element = element let text = element.querySelector(".z-padtop2").textContent // parse fandom(s) if (text.startsWith("Crossover - ")) { this.fandom = text.substring("Crossover - ".length, text.lastIndexOf(" - Rated: ")) } else { this.fandom = text.substring(0, text.lastIndexOf(" - Rated: ")) } } hide() { this.element.classList.add("hidden") } } let listings = [] for (let listing of listingElements) { listings.push(new Listing(listing)) } addCSS(".hidden {display: none}") for (let listing of listings) { for (let fandom of blocked) { if (listing.fandom.contains(blocked)) { listing.hide() } } }