Blocks BlockAdBlock scripts. Toggleable if required.
目前為
// ==UserScript==
// @name BlockBlockAdBlock
// @namespace ZOWEB
// @version 1
// @description Blocks BlockAdBlock scripts. Toggleable if required.
// @match *://*/*
// @run-at document-start
// @license MIT
// @noframes
// ==/UserScript==
function addFunction(func, exec) {
// wait for document.head
const int = setInterval(() => {
if (!document.head) return;
console.debug("Inserting script.");
const script = document.createElement("script");
script.textContent = "-" + func + (exec ? "()" : "");
document.head.appendChild(script);
setTimeout(script.remove.bind(script), 0);
clearInterval(int);
}, 0);
}
addFunction(function() {
let hasEvaled = false, firstEvalId, firstEvalCode;
const oldEval = window.eval;
window.eval = d => {
const id = Math.floor(Math.random() * 20), runChecker = Math.floor(Math.random() * 255).toString(16);
hasEvaled = true;
function b(checker) {
if (checker === runChecker) {
console.warn("bbab * Running eval script!");
oldEval(d);
} else console.error("bbab * Invalid checker! Eval will only run with the checker specified.");
}
if (localStorage.getItem("bbab") !== "disable") {
console.warn(" * ---- * --- * --- * ---- *");
console.warn("bbab * Eval script was blocked *");
console.warn("bbab * From:", (new Error()).stack.split("\n")[1]);
console.warn("bbab * [ To run this script, type the following into the console: ]");
console.warn("bbab * [ window._bbab_" + id + "(\"" + runChecker + "\") ]");
window["_bbab_" + id] = a => b(a);
} else {
console.warn("bbab * Letting through eval script as we are disabled.");
oldEval(d);
}
if (typeof firstEvalId === "undefined") {
firstEvalId = id;
firstEvalCode = runChecker;
}
};
// if we've visited this page multiple times add a popup to say so
if (localStorage.getItem("bbab.visited") === "yes") {
const elem = document.createElement("p");
elem.id = "BBAB_POPUP";
elem.style.position = "fixed";
elem.style.bottom = ".5em";
elem.style.right = ".5em";
elem.style.padding = "1em";
elem.style.backgroundColor = "#314159";
elem.style.color = "#eff4ff";
elem.style.borderRadius = "3px";
elem.style.fontFamily = "sans-serif";
elem.style.fontSize = "16px";
elem.style.zIndex = "999999";
const href = document.createElement("a");
href.href = "#";
href.style.color = "#99a9e6";
href.style.textDecoration = "underline";
const reloadLink = document.createElement("a");
reloadLink.href = "#";
reloadLink.style.color = "#99a9e6";
reloadLink.style.textDecoration = "underline";
reloadLink.textContent = "Reload to update";
reloadLink.onclick = location.reload.bind(location, true);
if (localStorage.getItem("bbab") !== "disable") {
elem.textContent = "Disabling your adblocker on pages you visit frequently will help them survive. ";
href.textContent = "Turn off BlockBlockAdBlock";
href.addEventListener("click", e => {
e.preventDefault();
localStorage.setItem("bbab", "disable");
elem.remove();
window["_bbab_" + firstEvalId](firstEvalCode);
});
} else {
elem.textContent = "Want to re-enable your adblocker? ";
href.textContent = "Turn on BlockBlockAdBlock";
href.addEventListener("click", e => {
e.preventDefault();
localStorage.setItem("bbab", "enable");
elem.textContent = "";
elem.appendChild(reloadLink);
});
}
elem.appendChild(href);
setTimeout(() => {
console.debug("Checking if we've been blocked");
if (hasEvaled) {
console.debug("Inserting elem");
document.body.appendChild(elem)
}
}, 3000);
}
localStorage.setItem("bbab.visited", "yes")
}, true);
console.info("You are being protected.");