Anti adblock detector

Removes most (not all) adblock detectors that ask you to disable your ad blocking extension.

이 스크립트 설치?
작성자 추천 스크립트

Anti Anti-debugger 스크립트도 사용해 보세요.

이 스크립트 설치
  1. // ==UserScript==
  2. // @name Anti adblock detector
  3. // @namespace https://greatest.deepsurf.us/en/users/670188-hacker09?sort=daily_installs
  4. // @version 2
  5. // @description Removes most (not all) adblock detectors that ask you to disable your ad blocking extension.
  6. // @author hacker09
  7. // @match *://*/*
  8. // @run-at document-start
  9. // @grant unsafeWindow
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. "use strict";
  14. if (location.host === "adsrff.web.sdo.com") { return location.replace("https://ff.web.sdo.com/web8/index.html#/home"); }
  15. class Stack extends Error {
  16. constructor(...a) {
  17. super(...a);
  18. }
  19. getStack(offset = 4) {
  20. return typeof this.stack === "string" ? this.stack.replace(/^Error\n +/, "").replace(/\n +/g, `\n${" ".repeat(offset)}`) : this.stack;
  21. }
  22. }
  23. const removedAds = [];
  24. /**
  25. * @type {Window & typeof globalThis} doc
  26. */
  27. const win = unsafeWindow;
  28. /**
  29. * @type {Document} doc
  30. */
  31. const doc = win.document;
  32. const MutationObserver = win.MutationObserver;
  33. /**
  34. * @argument {string} selector
  35. * @returns {HTMLElement | null} element
  36. */
  37. const $ = (selector) => doc.querySelector(selector);
  38. /**
  39. * @argument {string} selector
  40. * @returns {NodeListOf<HTMLElement> | null} element
  41. */
  42. const $$ = (selector) => doc.querySelectorAll(selector);
  43. const info = (that) => {
  44. console.info("RemoveAds: ", removedAds.push(that), "\nTarget:", that, "\nParentNode:", that.parentNode, "\nInnerText:", that.innerText);
  45. };
  46. const suffixList = {};
  47. const getRandomSuffix = (str) => {
  48. if (typeof suffixList[str] !== "string") {
  49. suffixList[str] = "";
  50. while (suffixList[str].length < 16) {
  51. suffixList[str] += (+`${Math.random()}`.substring(2)).toString(36).replace(suffixList[str].length === 0 ? /^\d+/ : "", "");
  52. }
  53. }
  54. return suffixList[str];
  55. };
  56. let localstorage;
  57. try {
  58. localstorage = win.localStorage;
  59. } catch (e) {
  60. console.info("RemoveAds: Tried to get `localStorage` but got an error - ", e);
  61. localstorage = {
  62. length: 0,
  63. key: () => null,
  64. getItem: () => null,
  65. setItem: () => { },
  66. removeItem: () => { },
  67. };
  68. }
  69. let sessionStorage;
  70. try {
  71. sessionStorage = win.sessionStorage;
  72. } catch (e) {
  73. console.info("RemoveAds: Tried to get `sessionStorage` but got an error - ", e);
  74. sessionStorage = {
  75. length: 0,
  76. key: () => null,
  77. getItem: () => null,
  78. setItem: () => { },
  79. removeItem: () => { },
  80. };
  81. }
  82.  
  83. if (location.hostname.endsWith(".ff14angler.com")) {
  84. const removeChild = win.Node.prototype.removeChild;
  85. win.Node.prototype.removeChild = function (e) {
  86. if (e.id === "contents") {
  87. console.info("RemoveAds: Tried to remove contents", e, "but rejected.\n", new Stack().getStack(9));
  88. return false;
  89. }
  90. return removeChild.bind(this)(e);
  91. };
  92. } else if ((location.host.includes("bbs.nga.cn") || location.host.includes("bbs.ngacn.cc")) && location.pathname.includes("adpage_insert")) {
  93. const stylesheet = document.createElement("style");
  94. stylesheet.innerText = "html, body, * { display: none!important; }";
  95. doc.body.appendChild(stylesheet);
  96. const jump = function jump() {
  97. if (win.getJump) {
  98. const _getJump = win.getJump.bind(win);
  99. win.getJump = function () { };
  100. _getJump();
  101. }
  102. };
  103. setInterval(jump, 10);
  104. } else if (location.hostname === "www.ruanyifeng.com") {
  105. console.info("RemoveAds: removed the anti-adb checker.");
  106. const c = setInterval(() => {
  107. const img = $('a > img[src*="wangbase.com/blogimg/asset/"]');
  108. if (img) {
  109. img.remove();
  110. } else {
  111. const entrySponsor = $(".entry-sponsor");
  112. if (entrySponsor) {
  113. entrySponsor.remove();
  114. clearInterval(c);
  115. }
  116. }
  117. }, 10);
  118. } else if (location.hostname.includes("mrcong.com")) {
  119. const style = document.createElement("style");
  120. style.innerText = "#fukie1{display:none !important}#fukie2{display:block !important}";
  121. document.head.appendChild(style);
  122. }
  123. const secretKey = `${Math.random().toString(36).substring(2)}${Math.random().toString(36).substring(2)}${Math.random().toString(36).substring(2)}`;
  124. class BlockAdBlock {
  125. constructor(...args) {
  126. if (args[0] !== secretKey) {
  127. console.info("RemoveAds: Got a call to construct BlockAdBlock but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  128. }
  129. }
  130. check(...args) {
  131. console.info("RemoveAds: Got a call to blockAdBlock.check but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  132. }
  133. clearEvent(...args) {
  134. console.info("RemoveAds: Got a call to blockAdBlock.clearEvent but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  135. }
  136. emitEvent(...args) {
  137. console.info("RemoveAds: Got a call to blockAdBlock.emitEvent but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  138. }
  139. setOption(...args) {
  140. console.info("RemoveAds: Got a call to blockAdBlock.setOption but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  141. }
  142. on(detected, fn) {
  143. this[detected === true ? "onDetected" : "onNotDetected"](fn);
  144. return this;
  145. }
  146. onDetected(...args) {
  147. console.info("RemoveAds: Got a call to blockAdBlock.onDetected but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  148. return this;
  149. }
  150. onNotDetected(...args) {
  151. if (typeof args[0] === "function") {
  152. args[0]();
  153. }
  154. console.info("RemoveAds: Got a call to blockAdBlock.onNotDetected but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  155. return this;
  156. }
  157. }
  158. const blockAdBlock = new BlockAdBlock(secretKey);
  159. const blockAdBlockProps = {
  160. configurable: false,
  161. enumerable: false,
  162. get: () => blockAdBlock,
  163. set: (...args) => {
  164. console.info("RemoveAds: Got a call to set window.blockAdBlock but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  165. },
  166. };
  167. const BlockAdBlockProps = {
  168. configurable: false,
  169. enumerable: false,
  170. get: () => BlockAdBlock,
  171. set: (...args) => {
  172. console.info("RemoveAds: Got a call to set window.BlockAdBlock but denied,\nwith arguments", ...args, ",\nin stack", new Stack().getStack(9));
  173. },
  174. };
  175. const fabList = ["fuckAdBlock", "blockAdBlock", "sniffAdBlock"];
  176. const FABList = ["FuckAdBlock", "BlockAdBlock", "SniffAdBlock"];
  177. fabList.forEach((n) => {
  178. if (Object.prototype.hasOwnProperty.bind(win)(n)) {
  179. win[n].__proto__ = new BlockAdBlock(secretKey);
  180. } else {
  181. Object.defineProperty(win, n, blockAdBlockProps);
  182. }
  183. });
  184. FABList.forEach((n) => {
  185. if (Object.prototype.hasOwnProperty.bind(win)(n)) {
  186. win[n].prototype = BlockAdBlock;
  187. } else {
  188. Object.defineProperty(win, n, BlockAdBlockProps);
  189. }
  190. });
  191.  
  192. const constantVariabls = [
  193. ["admiral", undefined],
  194. ["runAntiAdBlock", undefined],
  195. ["DHAntiAdBlocker", true],
  196. ["canRunAds", true],
  197. ["__jsadsuccess", true],
  198. ["adBlockNotDetected", () => { }],
  199. ["adBlockDetected", () => { }],
  200. ["adsBlocked", () => { }],
  201. ["importFAB", undefined],
  202. ["adblock", false],
  203. ["loadErrorTip", () => { }],
  204. ["checkAdBlocker", () => { }],
  205. ["var_do", false],
  206. ["ads", {}],
  207. ];
  208. for (const [name, value] of constantVariabls) {
  209. try {
  210. Object.defineProperty(win, name, {
  211. configurable: false,
  212. enumerable: true,
  213. get() {
  214. console.info(`RemoveAds: Got a call trying to get \`${name}\` but denied with returning`, value, ":\n", new Stack().getStack(9));
  215. return value;
  216. },
  217. set(v) {
  218. console.info(`RemoveAds: Got a call trying to set \`${name}\` to this below but denied:\n`, v, "\n", new Stack().getStack(9));
  219. },
  220. });
  221. } catch (e) {
  222. try {
  223. win[name] = value;
  224. delete win[name];
  225. Object.defineProperty(win, name, {
  226. configurable: false,
  227. enumerable: true,
  228. get() {
  229. console.info(`RemoveAds: Got a call trying to get \`${name}\` but denied with returning`, value, ":\n", new Stack().getStack(9));
  230. return value;
  231. },
  232. set(v) {
  233. console.info(`RemoveAds: Got a call trying to get \`${name}\` to this but denied:\n`, v, "\n", new Stack().getStack(9));
  234. },
  235. });
  236. console.info(`RemoveAds: Cannot set global variable \`${name}\` to`, value, "from", win[name], "because:\n", new Stack().getStack.bind(e)(9));
  237. } catch (err) {
  238. console.info(`RemoveAds: Cannot set global variable \`${name}\` to`, value, "because:\n", new Stack().getStack.bind(e)(9), "\nand\n", new Stack().getStack.bind(err)(9));
  239. }
  240. }
  241. }
  242.  
  243. sessionStorage.setItem("daau_dissmissed", "true");
  244. win.addEventListener("error", (e) => {
  245. const originalErrorHandler = e.target?.onerror;
  246. const onerror = originalErrorHandler?.toString?.();
  247. if (/([a-z]+)\.data=[a-z]+.ui,\1.build_ui\(\)|window\.adblock/i.test(onerror || "")) {
  248. sessionStorage.setItem("daau_dissmissed", "true");
  249. e.target.onerror = () => {
  250. console.info("RemoveAds: Got a call trying to trigger error handler to anti adb but denied:", originalErrorHandler);
  251. };
  252. }
  253. }, {
  254. capture: true,
  255. });
  256.  
  257. // let blockBlockAdBlockFlag = false;
  258. function removeAd() {
  259. if (!location.host.includes("getadmiral.com")) {
  260. Array.from($$(`body > :not([${getRandomSuffix("rmAd-admiral")}])`)).forEach((that) => {
  261. that.setAttribute(getRandomSuffix("rmAd-admiral"), "");
  262. if (that.querySelector('a[href^="https://getadmiral.com/pb"]')) {
  263. info(that);
  264. that.remove();
  265. }
  266. });
  267. }
  268. if (location.host.endsWith("gamepedia.com")) {
  269. const siderail = $("#siderail");
  270. if (siderail) { siderail.remove(); }
  271. const globalWrapper = $("#global-wrapper.with-siderail");
  272. if (globalWrapper) { globalWrapper.classList.remove("with-siderail"); }
  273. } else if (!location.host.includes("amplitude.com")) {
  274. try {
  275. const keys = [];
  276. const length = (localstorage || win.localStorage).length;
  277. for (let i = 0; i < length; i++) {
  278. keys.push((localstorage || win.localStorage).key(i));
  279. }
  280. keys.filter((k) => k.startsWith("amplitude_")).forEach((k) => {
  281. const c = (localstorage || win.localStorage).getItem(k);
  282. (localstorage || win.localStorage).removeItem(k);
  283. console.info("RemoveAds: Remove the track info from amplitude", removedAds.push([k, c]), "\n", `${k}: ${c}`);
  284. });
  285. } catch (e) { }
  286. }
  287. if (location.hostname.includes("aternos.org")) {
  288. const i = doc.querySelector("body > span i.fas.fa-ban");
  289. const c = win.$('body > div > div> div[style*="overflow: hidden"]');
  290. if (i || c) {
  291. c.children().appendTo(".page-content");
  292. i?.closest?.("body > span")?.remove?.();
  293. win.$(".body, .header").each(function () {
  294. this.style.setProperty("display", "");
  295. this.style.setProperty("height", "");
  296. });
  297. win.$("#start").each(function () {
  298. this._ready = true;
  299. });
  300. }
  301. }
  302. }
  303. document.addEventListener("DOMContentLoaded", () => {
  304. const callback = function () {
  305. removeAd();
  306. if (location.href.indexOf("www.baidu.com/s") !== -1) {
  307. Array.from($$(`#content_left .c-container:not([${getRandomSuffix("rmAd-baidu")}])`)).forEach((ele) => {
  308. ele.setAttribute(getRandomSuffix("rmAd-baidu"), "");
  309. if (ele.querySelector(".icon-unsafe-icon")) { ele.remove(); }
  310. if (!ele.attachShadow) {
  311. console.info("RemoveAds (shadowRoot): ", removedAds.push(ele), "\nTarget:", ele, "\nParentNode:", ele.parentNode, "\nInnerText", ele.innerText);
  312. const html = ele.outerHTML;
  313. const node = doc.createElement("div");
  314. ele.before(node);
  315. node.outerHTML = html;
  316. ele.remove();
  317. }
  318. });
  319. }
  320. };
  321. const observer = new MutationObserver(callback);
  322. observer.observe(doc.body, { attributes: true, childList: true, subtree: true });
  323. removeAd();
  324. });
  325. {
  326. const append = win.DocumentFragment.prototype.append;
  327. win.DocumentFragment.prototype.append = function (...nodes) {
  328. append.bind(this)(...nodes.filter((node) => {
  329. if (node === doc.body) {
  330. console.info("RemoveAds: Got a call trying to remove document.body but denied", ":\n", new Stack().getStack(9));
  331. return false;
  332. }
  333. return true;
  334. }));
  335. };
  336. }
  337. })();