Demonoid remove clutter

Removes VPN ads and donation messages

目前為 2022-01-19 提交的版本,檢視 最新版本

// ==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.0
// @description Removes VPN ads and donation messages
// @run-at      document-start
// @inject-into content
// @license     MIT
// ==/UserScript==

(function () {
	"use strict";
	
	const { HTMLUnknownElement } = window;


	function hide(element, state = true) {
		if (element && element.hidden !== state) {
			element.hidden = state;
		}
	}


	hide(document.documentElement);


	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);
	}
	
	
	if (typeof globalThis.XPCNativeWrapper === "function") {
		inject(XPCNativeWrapper.unwrap, (f) => exportFunction(f, window));
	} else {
		const script = document.createElement("script");
		script.text = `"use strict";(${inject})();`
		(document.head ?? document.documentElement).prepend(script);
		script.remove();
	}


	window.addEventListener("DOMContentLoaded", () => {
		let selector = ".user_donation_box,#share-buttons,#downloadbox a:first-of-type,#downloadbox br:first-of-type,#rss_feed_link br,#rss_feed_link2 br";


		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) {
			selector += `,${adElement.tagName}`;
			for (const classe of adElement.classList) {
				// Add class selector twice to increase specificity
				selector += `.${classe}.${classe}`;
			}
		}


		const style = document.createElement("style");
		style.textContent = `${selector}{display:none!important;}`;
		document.head.prepend(style);

		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"));
		}

		hide(document.documentElement, false);
	});
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址