GoGoBlocker

Block annoyances.

// ==UserScript==
// @name			GoGoBlocker
// @namespace		https://greasyfork.org/scripts?set=439787
// @homepage		https://greasyfork.org/scripts/424682-gogoblocker/
// @version			0.4.2
// @description		Block annoyances.
// @defaulticon		https://cdn.gogocdn.net/files/gogo/img/favicon.ico
// @author			V. H.
// @include			/^https?:\/\/(.*?\.)?((go){2}.+|vidstream|mcloud2?|str(eam)?ta\.?pe|mp4upload|videovard)\./
// @grant			unsafeWindow
// @grant			GM_log
// @grant			GM_addStyle
// @grant			GM_setValue
// @grant			GM_getValue
// @grant			GM_deleteValue
// @grant			GM_listValues
// @grant			window.onurlchange
// @grant			window.close
// @require			https://greasyfork.org/scripts/419588-uniq/code/UniQ.js
// @webRequest		[{"selector":"*://*.biz/*","action":"cancel"},{"selector":"*://*.xyz/*","action":"cancel"},{"selector":"*://*.bebi.com/*","action":"cancel"},{"selector":"*://pushyfen.com/*","action":"cancel"},{"selector":"*://absolutionbravery.com/*","action":"cancel"},{"selector":"*://cagothie.net/*","action":"cancel"},{"selector":"*://mydisuho.pro/*","action":"cancel"},{"selector":"*://*.cdn4ads.com/*","action":"cancel"},{"selector":"*://mellowpresence.com/*","action":"cancel"}]
// @compatible		Chrome
// @license			AFL-3.0
// @run-at			document-start
// ==/UserScript==

/**
 * AdBlock:
 * 	||runnersgunpowder.com$script
 * 	||links.services.disqus.com/api/sync.gif$image,domain=disqus.com|services.disqus.com|links.services.disqus.com,rewrite=abp-resource:1x1-transparent-gif
 * 	||gogoanime.*,vidstream.*,mcloud2.*,streamtape.*,mp4upload.*,strtape.*$popup
 */

void async function _script() {
	"use strict";
	
	if (unsafeWindow.location.hostname.endsWith(".xyz")) unsafeWindow.close();
	
	let a;
	
	unsafeWindow.console.clear = () => {};
	
	unsafeWindow.addEventListener("DOMContentLoaded", a = () => GM_addStyle(`
		.hidecss {
			opacity: 0 !important;
			visibility: hidden !important;
			display: none !important;
			width: 0 !important;
			height: 0 !important;
			pointer-events: none !important;
			touch-callout: none !important;
			user-select: none !important;
			top: -1 !important;
			left: -1 !important;
			position: absolute !important;
		}
	`));
	a();
	
	unsafeWindow._ibl = setInterval(() => {
		unsafeWindow.do_if(document.querySelectorAll(".adw, .afs_ads, .padPreload, #adb, .ad, .google-ad, .lay[id=lay], .plyr-overlay, iframe[style='display: none;'], iframe[src='about:blank'], iframe[style='width: 1px; height: 1px; opacity: 0;'], iframe[width='0']"), adws => {
			adws.forEach(adw => {
				GM_log("Ad removed", adw);
				unsafeWindow.incVal("ads", 0);
				
				adw.remove();
			});
			
			return true;
		});
		unsafeWindow.do_if(document.getElementById("videolink"), ln => {
			const main = document.getElementById("mainvideo");
			
			if (main) {
				GM_log("Video source loaded.");
				
				main.src = ln.innerText;
				
				ln.id = "videolonk";
			}
		});
		for (const elm of document.all) {
			if ((elm.id && /^\d{2}/.test(elm.id) && elm.tagName != "STYLE") || unsafeWindow.getComputedStyle(elm)["z-index"] >= 1147483647) {
				GM_log("Ads removed", elm);
				unsafeWindow.incVal("ads", 0);
				
				elm.remove();
			}
		}
		if (!location.hostname.includes("gogoanime")) {
			for (const elm of document.all) {
				if (elm.id && elm.id.length >= 5 && elm.tagName === "DIV" && elm.children.some(ch => ch.id && ch.id.length >= 3 && ch.tagName === "A")) {
					GM_log("Clickjack removed", elm);
					unsafeWindow.incVal("ads", 0);
					
					elm.classList.add("hidecss");
					elm.children.forEach(ch => ch.remove());
				} else if (elm.tagName === "DIV" && elm.style.zIndex >= 10000) {
					GM_log("Clickjack removed", elm);
					unsafeWindow.incVal("ads", 0);
					
					elm.classList.add("hidecss");
					elm.remove();
				}
			}
			
			for (const frm of document.getElementsByTagName("iframe")) {
				if (!frm.src || frm.src.startsWith("about:blank") || frm.src.startsWith("javascript:") || (frm.style.opacity == "0" && frm.style.width == "1px")) {
					GM_log("iframe removed", frm);
					unsafeWindow.incVal("ads", 0);
					
					frm.classList.add("hidecss");
					frm.remove();
				}
			}
		}
		
		unsafeWindow.parseCookies().erase("direct_ads").set();
	}, 500);
	
	
	unsafeWindow.interWrite();
	unsafeWindow.interWrite.add(function write(...args) {
		GM_log("dwrite blocked.");
		unsafeWindow.incVal("ads", 0);
		
		return true;
	});
	
	unsafeWindow.interInter();
	unsafeWindow.interInter.add(function setInterval(fn, int, ...dat) {
		GM_log("Inter", fn, int, ...dat);
	});
	
	unsafeWindow.interEvent();
	unsafeWindow.interEvent.add(function addEventListener(event, fn, ...capture) {
		if (["mousedown", "mousewheel", "mouseup", "contextmenu", "dblclick"].includes(event) || event.startsWith("ad") || ((this === document || this === document.body) && ["click"].includes(event))) GM_log("Blocked Event", event, fn, ...capture);
		else return this ? unsafeWindow.interEvent.interOrig.bind(this)(event, fn, ...capture) : unsafeWindow.interEvent.interOrig(event, fn, ...capture);
		
		unsafeWindow.incVal("ads", 0);
		
		return this;
	});
	
	let o;
	unsafeWindow.interWinopen();
	unsafeWindow.interWinopen.add((o = function open(url, name, ...args) {
		GM_log("Blocked window", name, url);
		unsafeWindow.incVal("ads", 0);
		
		return Object.assign(this, { open: o }) || true;
	}).bind(unsafeWindow || window));
	
	unsafeWindow.interXHR();
	unsafeWindow.interXHR.add(function open(method, url, ...rest) {
		if (url.includes(".xyz") || url.includes(".biz")) {
			GM_log("XHR Blocked:", method, url, ...rest);
			unsafeWindow.incVal("ads", 0);
			
			return true;
		} else GM_log("XHR", method, url, ...rest);
		
		return false;
	});
}();