Anti Baha Anti ad block

anit anit ad block

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Anti Baha Anti ad block
// @namespace   mmis1000.me
// @description anit anit ad block
// @include     http://*.gamer.com.tw/*
// @include     https://*.gamer.com.tw/*
// @version     1.3.0
// @grant       none
// @run-at document-start
// ==/UserScript==
var debug = 0;
var injects = [
  {
    match: /var AntiAd/g,
    process: function (str) {
      return str.replace(/var AntiAd([\r\n]|.)*\(AntiAd\);/, '');
    }
  },
  {
    match: /var mercyadblock/g,
    process: function (str) {
      return str.replace(/var mercyadblock(.|\r|\n)+insideSecondaryfunc\(2, event\);(.|\r|\n)*\}\);/, '');
    }
  }
]
function addJS_Node(text, s_URL, funcToRun) {
  var D = document;
  var scriptNode = D.createElement('script');
  scriptNode.type = 'text/javascript';
  if (text) scriptNode.textContent = text;
  if (s_URL) scriptNode.src = s_URL;
  if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
  var targ = D.getElementsByTagName('head') [0] || D.body || D.documentElement;
  //--- Don't error check here. if DOM not available, should throw error.
  targ.appendChild(scriptNode);
}
function log() {
  if (!debug) return;
  console.log('aborted AntiAd');
  console.log((new Error).stack);
}
Object.defineProperty(window, 'mobileBigBanner', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: true
});
Object.defineProperty(window, 'AntiAd', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: {
  }
});
Object.defineProperty(window.AntiAd, 'block', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: log
});
Object.defineProperty(window.AntiAd, 'check', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: log
});
Object.freeze && Object.freeze(window.AntiAd);

Object.defineProperty(window, 'mercyadblock', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: {
  }
});
Object.defineProperty(window.mercyadblock, 'show', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: log
});
Object.defineProperty(window.mercyadblock, 'hide', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: hide
});
Object.freeze && Object.freeze(window.mercyadblock);

function listener(zEvent) {
  var matched = false;
  var text = zEvent.target.textContent;
  
  console.log(text);
  
  injects.forEach(function (item) {
    if (item.match.test(text)) {
      matched = true;
      text = item.process(text);
      
      if (!debug) return;
      
      console.log('matched');
      console.log(text);
      console.log(item);
    }
  })
  
  if (matched) {
    addJS_Node(text);
    zEvent.stopPropagation();
    zEvent.preventDefault();
    zEvent.target.parentElement.removeChild(zEvent.target);
    window.removeEventListener('beforescriptexecute', listener)
    
    if (!debug) return;
    
    console.log(zEvent.target.textContent)
    console.log('AntiAd script killed. Cleaned script:')
    console.log(text)
  }
}
window.addEventListener('beforescriptexecute', listener, true);