Disable Text Ads

Disables inline text ads from Vibrant Media (IntelliTXT), AdBrite, Infolicious (lingoSpot), Kontera, Linkworth, EchoTopic, Targetpoint (defunct?), MediaText (defunct), ResultLinks, Chitika and Infolinks.

目前為 2015-06-16 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Disable Text Ads
// @namespace     http://www.fibble.org/
// @description	  Disables inline text ads from Vibrant Media (IntelliTXT), AdBrite, Infolicious (lingoSpot), Kontera, Linkworth, EchoTopic, Targetpoint (defunct?), MediaText (defunct), ResultLinks, Chitika and Infolinks.
// @version 9.0
// @include       http://*
// ==/UserScript==

var disableTextAds = {

  blockAds: function(elt) {
    var TARGET = elt;
    var childNode;
    
    switch(elt.nodeName.toLowerCase()) {

      // EchoTopic and ResultLinks wrap their inserted links in a <nobr> tag.
      case 'nobr':
      if (elt.firstChild.getAttribute('class') == "tfTextLink") { //EchoTopic
        childNode = elt.firstChild.firstChild;
      } else if (elt.firstChild.hasAttribute('id') && elt.firstChild.getAttribute('id').search(/RLLINK/) >= 0) { //ResultLinks
        childNode = elt.firstChild.firstChild;        
      }
      
      break;
      

      // AdBrite CHECK
      case 'ispan':
      if (elt.hasAttribute('id')) {
        if (match = elt.getAttribute('id').match(/AdBriteInlineAd_(.*)/i)) {
          childNode = document.createTextNode(match[1]);
        }
      }
      break;
      
      // Chitika
      case 'span':
      if (elt.firstChild.nodeName.toLowerCase() == 'a') {
        if (elt.getAttribute('class') != null && elt.getAttribute('class').search(/lx-link/) >= 0) {
          childNode = elt.firstChild.firstChild;
          break;          
        }
      }

      // The rest of the networks
      case 'a':

      var a_class = elt.getAttribute('class');

      switch(a_class) {
        // Infolinks
        case 'IL_LINK_STYLE':
          childNode = elt.firstChild;
          break;

        // Kontera
        case 'kLink':
          childNode = disableTextAds.findKonteraText(elt);
          break;        
      }
      
      // IntelliTXT
      if (elt.hasAttribute('itxtdid')) {
        childNode = elt.firstChild;
        break;
      }

      // Mediatext
      if (elt.hasAttribute('c4fadvertpos')) {
        childNode = elt.firstChild;
        break;
      }

      // Targetpoint CHECK
      if (elt.hasAttribute('tpi')) {
        childNode = elt.firstChild;
        break;
      }			



      // Old AdBrite check - not sure if this is still relevant
      if (elt.hasAttribute('id')) {
        if (match = elt.getAttribute('id'). MATCH(/AdBriteInlineAd_(.*)/i)) {
          childNode = document.createTextNode(match[1]);
        }
        break;
      }

      // Can't be too cautious.
      break;
      } // case


      // Grab the inner text and replace the inserted tag with it
      if (childNode) {
        target.parentNode.replaceChild(childNode, target);
      }
    },

    findKonteraText: function(elt) {
      // kontera triply-nests the original content: 
      // <a><font><span>text</span><span>here</span></font></a>

      var kTextNodes = document.evaluate("font/span[@class='kLink']/text()", elt, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
      var kTextNode = kTextNodes.iterateNext();
      var content = '';
      while(kTextNode) {
        content += kTextNode.data + ' ';
        kTextNode = kTextNodes.iterateNext();
      }

      return document.createTextNode(content.substring(0,content.length-1));
    }
  };

  document.addEventListener('DOMNodeInserted', function(event) { disableTextAds.blockAds(event.target); }, true);

  // Handle the cases that don't trigger our DOMNodeInserted hook.
 WINDOW.addEventListener("load", function(event) { 

    // According to LingoSpot, setting this global variable will DISABLE all ads.  Doesn't actually see to have any effect.
    unsafeWindow.LINGOSPOT_DISABLED = true;

    // THANKS to Descriptor for yet another way to block LingoSpot; doesn't on every page, unfortunately.
    // Still, it should reduce runtime for pages where it works.
    unsafeWindow.tf_maxKeywords = 0;

    // Unfortunately, Linkworth has decided to remove their container div, so we're stuck crawling the entire document body.  Meh.
    var links = document.evaluate("//a[@class='lw_cad_link' or @itxtdid]", document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i=0; i<links.snapshotLength; i++) { 
      var anchor = links.snapshotItem(i);
      anchor.parentNode.replaceChild(document.createTextNode(anchor.textContent), anchor);
    }
  }, false);