Demonoid remove clutter

Removes ads and VPN shilling on Demonoid

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Demonoid remove clutter
// @namespace   jxq8p6u6r9wtn2f6617i
// @match       https://demonoid.is/*
// @match       https://www.demonoid.is/*
// @match       https://dnoid.pw/*
// @match       https://www.dnoid.pw/*
// @match       https://dnoid.to/*
// @match       https://www.dnoid.to/*
// @grant       none
// @version     1.2.1
// @description Removes ads and VPN shilling on Demonoid
// @run-at      document-start
// @inject-into content
// @license     MIT
// ==/UserScript==

(function () {
	"use strict";

	const { HTMLUnknownElement } = window;


	function hide(element, state = true) {
		if (!element) {
			return;
		}

		element.hidden = state;
		if (state) {
			element.style.setProperty("display", "none", "important");
		} else {
			element.style.removeProperty("display");
		}
	}


	function inject(unwrap = (x)=>x, exporter = unwrap) {
		const proxyHandler = new window.Object();
		proxyHandler.apply = exporter(function (write, that, args) {
			if (args[0]?.toLowerCase?.().indexOf?.("<script") === -1) {
				return write.apply(that, args);
			}
		});

		const doc = unwrap(Document.prototype);
		doc.write = new window.Proxy(doc.write, proxyHandler);
	}


	let unsafeDoc = document;

	if (typeof globalThis.XPCNativeWrapper === "function") {
		inject(XPCNativeWrapper.unwrap, (f) => exportFunction(f, window));
		// Why is the Firefox sandbox so weird
		unsafeDoc = XPCNativeWrapper.unwrap(unsafeDoc);
	} else {
		const script = document.createElement("script");
		script.text = `"use strict";(${inject})();`;
		(document.head ?? document.documentElement).prepend(script);
		script.remove();
	}


	hide(document.documentElement);


	const sheet = new CSSStyleSheet();
	sheet.replace("#share-buttons,#downloadbox a:first-of-type,#downloadbox br:first-of-type,#rss_feed_link br,#rss_feed_link2 br,center a[href$='.php'] img[alt='']{display:none!important;}");
	// Copy to unprivileged page scope array or this won't work in Firefox
	unsafeDoc.adoptedStyleSheets = window.Array.from([sheet].concat(document.adoptedStyleSheets));



	window.addEventListener("DOMContentLoaded", () => {
		// Hide big VPN message
		let adElement = document.evaluate(".//*[contains(text(), 'Get VPN')]", document.body, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
		while (adElement && !(adElement instanceof HTMLUnknownElement)) {
			adElement = adElement.parentNode;
		}

		if (adElement?.tagName) {
			for (const ad of document.getElementsByTagName(adElement.tagName)) {
				hide(ad);
			}
		}


		// Hide big black whitelist box
		adElement = document.evaluate(".//*[contains(text(), 'Ad-Blocker')]/ancestor-or-self::table", document.body, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
		hide(adElement);


		hide(document.body.querySelector("td > hr + span")?.closest("tr")); // Sponsored Links box on torrent pages

		const btcNags = document.body.querySelectorAll("a[href^='bitcoin:']");
		for (const nag of btcNags) {
			hide(nag.closest("span, p, div.block"));
		}
	});


	window.addEventListener("DOMContentLoaded", hide.bind(null, document.documentElement, false));
})();