Demonoid remove clutter

Removes VPN ads and donation messages

Versione datata 29/06/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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.1
// @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;
		}
	}


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


	hide(document.documentElement);


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


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