Disarm Adblock Detectors

Few utils which help to bypass Adblock detectors

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/7465/43841/Disarm%20Adblock%20Detectors.js

  1. /*jslint browser: true, devel: true */
  2. /*global unsafeWindow, exportFunction */
  3.  
  4. var DAD = (function (window, unsafeWindow) {
  5. "use strict";
  6. var utils, debug,
  7. slice = Array.prototype.slice;
  8. function noop() {
  9. }
  10. function injectCSS(css) {
  11. var style,
  12. head = document.getElementsByTagName("head")[0];
  13. if (head) {
  14. style = document.createElement("style");
  15. style.textContent = css;
  16. style.type = "text/css";
  17. head.appendChild(style);
  18. }
  19. }
  20. function wrapValue(value, writable) {
  21. var wrapper;
  22. writable = !!writable;
  23. if (value instanceof Function) {
  24. wrapper = exportFunction(value, unsafeWindow);
  25. } else if (value instanceof Array) {
  26. wrapper = exportProperties(new unsafeWindow.Array(), value, writable);
  27. } else if (value instanceof Object) {
  28. wrapper = exportProperties(new unsafeWindow.Object(), value, writable);
  29. }
  30. return wrapper || value;
  31. }
  32. function wrapArgs(args) {
  33. var index, value;
  34. args = wrapValue(args, true);
  35. for (index = args.length - 1; index >= 0; --index) {
  36. value = args[index];
  37. if (typeof value === "function" && !value.isProxy) {
  38. createProxy(args, index, true);
  39. }
  40. }
  41. return args;
  42. }
  43. function exportProperty(target, name, value, writable) {
  44. writable = !!writable;
  45. if (debug) {
  46. console.log("export property " + name);
  47. }
  48. var descriptor = {
  49. configurable: false,
  50. enumerable: true,
  51. value: wrapValue(value, writable),
  52. writable: writable
  53. };
  54. try {
  55. Object.defineProperty(target, name, descriptor);
  56. } catch (exception) {
  57. console.error(exception);
  58. }
  59. return target[name];
  60. }
  61. function exportProperties(target, object, writable) {
  62. writable = !!writable;
  63. var index, key;
  64. if (object instanceof Array) {
  65. for (index = object.length - 1; index >= 0; --index) {
  66. exportProperty(target, index, object[index], writable);
  67. }
  68. } else if (object instanceof Object) {
  69. for (key in object) {
  70. if (object.hasOwnProperty(key)) {
  71. exportProperty(target, key, object[key], writable);
  72. }
  73. }
  74. }
  75. return target;
  76. }
  77. function createProxy(target, name, fn, writable) {
  78. if (debug) {
  79. console.log("createProxy", arguments);
  80. }
  81. var caller, handler, proxy,
  82. native = target[name];
  83.  
  84. if (native.isProxy) {
  85. console.warn("method " + name + " of", target, "is already a proxy");
  86. } else {
  87. caller = function (args) {
  88. return native.apply(target, wrapArgs(args));
  89. };
  90. if (typeof fn === "function") {
  91. writable = !!writable;
  92. handler = function () {
  93. return fn(caller, wrapArgs(slice.call(arguments)));
  94. };
  95. } else {
  96. writable = !!fn;
  97. handler = function () {
  98. return caller(slice.call(arguments));
  99. };
  100. }
  101. proxy = exportProperty(target, name, handler, writable);
  102. proxy.isProxy = true;
  103. }
  104. return target[name];
  105. }
  106. function extractString(script, options) {
  107. var endIndex, string,
  108. startIndex = 0;
  109.  
  110. options = options || {};
  111. if (options.hasOwnProperty("before")) {
  112. startIndex = script.indexOf(options.before) + options.before.length;
  113. }
  114. if (!options.hasOwnProperty("separator")) {
  115. options.separator = "'";
  116. }
  117.  
  118. if (!options.hasOwnProperty("start")) {
  119. options.start = "";
  120. }
  121. if (startIndex > -1) {
  122. startIndex = script.indexOf(options.separator + options.start, startIndex) + 1;
  123. endIndex = script.indexOf(options.separator, startIndex);
  124.  
  125. string = script.substring(startIndex, endIndex);
  126. } else {
  127. string = null;
  128. }
  129. return string;
  130. }
  131. function DAD(filter, config) {
  132. if (filter instanceof RegExp) {
  133. if (!filter.test(location.href)) {
  134. return;
  135. }
  136. } else {
  137. config = filter;
  138. }
  139. if (typeof config === "function") {
  140. try {
  141. config = config(unsafeWindow, utils);
  142. } catch (exception) {
  143. console.error(exception);
  144. }
  145. }
  146. debug = !!config.debug;
  147. if (typeof config.css === "string") {
  148. injectCSS(config.css);
  149. }
  150. if (typeof config.exports === "object") {
  151. exportProperties(unsafeWindow, config.exports);
  152. }
  153. if (typeof config.init === "function") {
  154. window.addEventListener("DOMContentLoaded", function () {
  155. try {
  156. config.init();
  157. } catch (exception) {
  158. console.error(exception);
  159. }
  160. }, true);
  161. }
  162. }
  163. utils = {
  164. noop: noop,
  165. createProxy: createProxy,
  166. extractString: extractString
  167. };
  168. return DAD;
  169. }(this, unsafeWindow));

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址