Demonoid remove clutter

Removes VPN ads and donation messages

Mint 2022.06.29.. Lásd a legutóbbi verzió

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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