BlockBlockAdBlock

Blocks BlockAdBlock scripts. Toggleable if required.

安装此脚本?
作者推荐脚本

您可能也喜欢Wikipedia preview

安装此脚本
  1. // ==UserScript==
  2. // @name BlockBlockAdBlock
  3. // @namespace ZOWEB
  4. // @version 3
  5. // @description Blocks BlockAdBlock scripts. Toggleable if required.
  6. // @match *://*/*
  7. // @run-at document-start
  8. // @license MIT
  9. // @noframes
  10. // ==/UserScript==
  11.  
  12. function addFunction(func, exec) {
  13. // wait for document.head
  14. const int = setInterval(() => {
  15. if (!document.head) return;
  16.  
  17. console.debug("Inserting script.");
  18. const script = document.createElement("script");
  19. script.textContent = "-" + func + (exec ? "()" : "");
  20. document.head.appendChild(script);
  21. setTimeout(script.remove.bind(script), 0);
  22.  
  23. clearInterval(int);
  24. }, 0);
  25. }
  26.  
  27. addFunction(function() {
  28. let hasEvaled = false, firstEvalId, firstEvalCode;
  29.  
  30. const oldEval = window.eval;
  31.  
  32. function runEval(d) {
  33. const id = Math.floor(Math.random() * 20), runChecker = Math.floor(Math.random() * 255).toString(16);
  34.  
  35. function b(checker) {
  36. if (checker === runChecker) {
  37. console.warn("bbab * Running eval script!");
  38. return oldEval(d);
  39. } else console.error("bbab * Invalid checker! Eval will only run with the checker specified.");
  40. }
  41.  
  42. if (!hasEvaled) {
  43. hasEvaled = true;
  44. firstEvalId = id;
  45. firstEvalCode = runChecker;
  46.  
  47. runFirstTime();
  48. }
  49.  
  50. if (localStorage.getItem("bbab") !== "disable") {
  51. console.warn(" * ---- * --- * --- * ---- *");
  52. console.warn("bbab * Eval script was blocked *");
  53. console.warn("bbab * From:", (new Error()).stack.split("\n")[1]);
  54. console.warn("bbab * [ To run this script, type the following into the console: ]");
  55. console.warn("bbab * [ window._bbab_" + id + "(\"" + runChecker + "\") ]");
  56. console.warn("bbab * [ To print this script, type the following into the console: ]");
  57. console.warn("bbab * [ window._bbab_p_" + id + " ]");
  58.  
  59. window["_bbab_" + id] = a => b(a);
  60. window["_bbab_" + id].toString = () => "[function BlockBlockAdBlock]";
  61. window["_bbab_p_" + id] = d;
  62. } else {
  63. console.warn("bbab * Letting through eval script as we are disabled.");
  64. return oldEval(d);
  65. }
  66.  
  67. return new Error("Eval script was blocked.");
  68. }
  69.  
  70. window.eval = d => runEval(d);
  71. window.eval.toString = () => "function eval() {\n [native code]\n}";
  72. window.eval.toString.toString = () => "function toString() {\n [native code]\n}";
  73.  
  74. const elem = document.createElement("p");
  75. const targeter = document.createElement("button");
  76. const hider = document.createElement("button");
  77.  
  78. function runFirstTime() {
  79. console.info("Inserting popup if enabled");
  80.  
  81. // if we've visited this page multiple times add a popup to say so
  82. if (localStorage.getItem("bbab.visited") === "yes") {
  83. elem.id = "BBAB_POPUP";
  84. elem.style.position = "fixed";
  85. elem.style.bottom = ".5em";
  86. elem.style.right = ".5em";
  87. elem.style.padding = "1em";
  88. elem.style.backgroundColor = "#314159";
  89. elem.style.color = "#eff4ff";
  90. elem.style.borderRadius = "3px";
  91. elem.style.fontFamily = "sans-serif";
  92. elem.style.fontSize = "16px";
  93. elem.style.zIndex = "999999";
  94.  
  95. const href = document.createElement("a");
  96. href.href = "#";
  97. href.style.color = "#99a9e6";
  98. href.style.textDecoration = "underline";
  99.  
  100. const reloadLink = document.createElement("a");
  101. reloadLink.href = "#";
  102. reloadLink.style.color = "#99a9e6";
  103. reloadLink.style.textDecoration = "underline";
  104. reloadLink.textContent = "Reload to update";
  105. reloadLink.onclick = location.reload.bind(location, true);
  106.  
  107. const antiDMCA = document.createElement("small");
  108. antiDMCA.style.fontSize = "0.75em";
  109. antiDMCA.style.display = "none";
  110. antiDMCA.textContent = "Note: blocking BlockAdBlock is not against the DMCA (as much as they want you to think it is)";
  111. window.addEventListener("keydown", e => {
  112. if (e.key !== "F12") return;
  113. antiDMCA.style.display = "";
  114. });
  115.  
  116. if (localStorage.getItem("bbab") !== "disable") {
  117. elem.textContent = "Disabling your adblocker on pages you visit frequently will help them survive. ";
  118. href.textContent = "Turn off BlockBlockAdBlock";
  119.  
  120. href.addEventListener("click", e => {
  121. e.preventDefault();
  122.  
  123. localStorage.setItem("bbab", "disable");
  124.  
  125. elem.remove();
  126. window["_bbab_" + firstEvalId](firstEvalCode);
  127. });
  128. } else {
  129. elem.textContent = "";
  130. href.textContent = "Enable BBAB";
  131.  
  132. href.addEventListener("click", e => {
  133. e.preventDefault();
  134.  
  135. localStorage.setItem("bbab", "enable");
  136.  
  137. elem.textContent = "";
  138. elem.appendChild(reloadLink);
  139. });
  140. }
  141.  
  142. elem.appendChild(href);
  143. elem.appendChild(document.createElement("br"));
  144. elem.appendChild(antiDMCA);
  145.  
  146. console.debug("Inserting elem");
  147. document.body.appendChild(elem);
  148. }
  149. localStorage.setItem("bbab.visited", "yes");
  150. }
  151.  
  152. window.onload = () => {
  153. console.debug("Checking if we've been blocked");
  154.  
  155. // add another element incase BlockAdBlock does magic
  156. // which seems to hide from MutationObservers????????
  157. targeter.style.zIndex = "999999";
  158. targeter.style.position = "fixed";
  159. targeter.style.left = "4em";
  160. targeter.style.bottom = ".5em";
  161. targeter.style.borderRadius = "3px";
  162. targeter.style.backgroundColor = "#eff4ff";
  163. targeter.style.border = "1px solid #314159";
  164. targeter.style.color = "#314159";
  165. targeter.style.cursor = "pointer";
  166. targeter.style.fontFamily = "sans-serif";
  167. targeter.style.fontSize = "16px";
  168. targeter.style.padding = ".1em .3em";
  169. targeter.textContent = "Delete Annoying Element";
  170.  
  171. hider.style.zIndex = "999999";
  172. hider.style.position = "fixed";
  173. hider.style.left = ".5em";
  174. hider.style.bottom = ".5em";
  175. hider.style.borderRadius = "3px";
  176. hider.style.backgroundColor = "#eff4ff";
  177. hider.style.border = "1px solid #314159";
  178. hider.style.color = "#314159";
  179. hider.style.cursor = "pointer";
  180. hider.style.fontFamily = "sans-serif";
  181. hider.style.fontSize = "16px";
  182. hider.style.padding = ".1em .3em";
  183. hider.style.transition = "200ms ease-out";
  184. hider.textContent = "[Hide]";
  185.  
  186. function toggleElements() {
  187. if (localStorage.getItem("bbab.visibility") === "visible") {
  188. targeter.style.display = "none";
  189. elem.style.display = "none";
  190. localStorage.setItem("bbab.visibility", "hidden");
  191.  
  192. hider.style.bottom = "-.7em";
  193. hider.textContent = "____";
  194. } else {
  195. hider.textContent = "[Hide]";
  196. targeter.style.display = "";
  197. elem.style.display = "";
  198. localStorage.setItem("bbab.visibility", "visible");
  199.  
  200. hider.style.bottom = ".5em";
  201. }
  202. }
  203.  
  204. // toggle twice to go back to normal
  205. toggleElements();
  206. toggleElements();
  207.  
  208. document.body.appendChild(hider);
  209. document.body.appendChild(targeter);
  210.  
  211. hider.onclick = () => toggleElements();
  212. targeter.onclick = () => {
  213. const overlay = document.createElement("div");
  214. overlay.style.position = "fixed";
  215. overlay.style.zIndex = "99999";
  216. overlay.style.background = "rgba(255,255,255,0.6)";
  217. overlay.style.cursor = "select";
  218. overlay.style.pointerEvents = "none";
  219. overlay.style.border = "1px dashed black";
  220. document.body.appendChild(overlay);
  221.  
  222. targeter.style.pointerEvents = "none";
  223. targeter.style.opacity = "0.4";
  224. hider.style.pointerEvents = "none";
  225. hider.style.opacity = "0.4";
  226. elem.style.pointerEvents = "none";
  227. elem.style.opacity = "0.4";
  228.  
  229. let target = {remove(){}};
  230. function mouseMove(e) {
  231. target = e.target;
  232. const targetPos = target.getBoundingClientRect();
  233.  
  234. overlay.style.top = `${targetPos.top}px`;
  235. overlay.style.left = `${targetPos.left}px`;
  236. overlay.style.width = `${targetPos.width}px`;
  237. overlay.style.height = `${targetPos.height}px`;
  238. }
  239.  
  240. function mouseDown(e) {
  241. e.preventDefault();
  242.  
  243. window.removeEventListener("mousemove", mouseMove);
  244. window.removeEventListener("mousedown", mouseDown);
  245. window.removeEventListener("keydown", keyDown);
  246. target.remove();
  247. overlay.remove();
  248.  
  249. targeter.style.pointerEvents = "";
  250. targeter.style.opacity = "";
  251. hider.style.pointerEvents = "";
  252. hider.style.opacity = "";
  253. elem.style.pointerEvents = "";
  254. elem.style.opacity = "";
  255. }
  256.  
  257. function keyDown(e) {
  258. console.log(e.key);
  259. if (e.key !== "Esc") return;
  260.  
  261. e.preventDefault();
  262.  
  263. window.removeEventListener("mousemove", mouseMove);
  264. window.removeEventListener("mousedown", mouseDown);
  265. window.removeEventListener("keydown", keyDown);
  266. overlay.remove();
  267.  
  268. targeter.style.pointerEvents = "";
  269. targeter.style.opacity = "";
  270. hider.style.pointerEvents = "";
  271. hider.style.opacity = "";
  272. elem.style.pointerEvents = "";
  273. elem.style.opacity = "";
  274. }
  275.  
  276. window.addEventListener("mousemove", mouseMove);
  277. window.addEventListener("mousedown", mouseDown);
  278. window.addEventListener("keydown", keyDown);
  279. };
  280.  
  281. if (localStorage.getItem("bbab") !== "disable" && document.getElementById("babasbmsgx") !== null) document.getElementById("babasbmsgx").remove();
  282.  
  283. };
  284. }, true);
  285.  
  286. console.info("You are being protected.");