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.

  1. // ==UserScript==
  2. // @name Disable Text Ads
  3. // @namespace http://www.fibble.org/
  4. // @description Disables inline text ads from Vibrant Media (IntelliTXT), AdBrite, Infolicious (lingoSpot), Kontera, Linkworth, EchoTopic, Targetpoint (defunct?), MediaText (defunct), ResultLinks, Chitika and Infolinks.
  5. // @version 9.0
  6. // @include http://*
  7. // ==/UserScript==
  8.  
  9. var disableTextAds = {
  10.  
  11. blockAds: function(elt) {
  12. var TARGET = elt;
  13. var childNode;
  14. switch(elt.nodeName.toLowerCase()) {
  15.  
  16. // EchoTopic and ResultLinks wrap their inserted links in a <nobr> tag.
  17. case 'nobr':
  18. if (elt.firstChild.getAttribute('class') == "tfTextLink") { //EchoTopic
  19. childNode = elt.firstChild.firstChild;
  20. } else if (elt.firstChild.hasAttribute('id') && elt.firstChild.getAttribute('id').search(/RLLINK/) >= 0) { //ResultLinks
  21. childNode = elt.firstChild.firstChild;
  22. }
  23. break;
  24.  
  25. // AdBrite CHECK
  26. case 'ispan':
  27. if (elt.hasAttribute('id')) {
  28. if (match = elt.getAttribute('id').match(/AdBriteInlineAd_(.*)/i)) {
  29. childNode = document.createTextNode(match[1]);
  30. }
  31. }
  32. break;
  33. // Chitika
  34. case 'span':
  35. if (elt.firstChild.nodeName.toLowerCase() == 'a') {
  36. if (elt.getAttribute('class') != null && elt.getAttribute('class').search(/lx-link/) >= 0) {
  37. childNode = elt.firstChild.firstChild;
  38. break;
  39. }
  40. }
  41.  
  42. // The rest of the networks
  43. case 'a':
  44.  
  45. var a_class = elt.getAttribute('class');
  46.  
  47. switch(a_class) {
  48. // Infolinks
  49. case 'IL_LINK_STYLE':
  50. childNode = elt.firstChild;
  51. break;
  52.  
  53. // Kontera
  54. case 'kLink':
  55. childNode = disableTextAds.findKonteraText(elt);
  56. break;
  57. }
  58. // IntelliTXT
  59. if (elt.hasAttribute('itxtdid')) {
  60. childNode = elt.firstChild;
  61. break;
  62. }
  63.  
  64. // Mediatext
  65. if (elt.hasAttribute('c4fadvertpos')) {
  66. childNode = elt.firstChild;
  67. break;
  68. }
  69.  
  70. // Targetpoint CHECK
  71. if (elt.hasAttribute('tpi')) {
  72. childNode = elt.firstChild;
  73. break;
  74. }
  75.  
  76.  
  77.  
  78. // Old AdBrite check - not sure if this is still relevant
  79. if (elt.hasAttribute('id')) {
  80. if (match = elt.getAttribute('id'). MATCH(/AdBriteInlineAd_(.*)/i)) {
  81. childNode = document.createTextNode(match[1]);
  82. }
  83. break;
  84. }
  85.  
  86. // Can't be too cautious.
  87. break;
  88. } // case
  89.  
  90.  
  91. // Grab the inner text and replace the inserted tag with it
  92. if (childNode) {
  93. target.parentNode.replaceChild(childNode, target);
  94. }
  95. },
  96.  
  97. findKonteraText: function(elt) {
  98. // kontera triply-nests the original content:
  99. // <a><font><span>text</span><span>here</span></font></a>
  100.  
  101. var kTextNodes = document.evaluate("font/span[@class='kLink']/text()", elt, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
  102. var kTextNode = kTextNodes.iterateNext();
  103. var content = '';
  104. while(kTextNode) {
  105. content += kTextNode.data + ' ';
  106. kTextNode = kTextNodes.iterateNext();
  107. }
  108.  
  109. return document.createTextNode(content.substring(0,content.length-1));
  110. }
  111. };
  112.  
  113. document.addEventListener('DOMNodeInserted', function(event) { disableTextAds.blockAds(event.target); }, true);
  114.  
  115. // Handle the cases that don't trigger our DOMNodeInserted hook.
  116. WINDOW.addEventListener("load", function(event) {
  117.  
  118. // According to LingoSpot, setting this global variable will DISABLE all ads. Doesn't actually see to have any effect.
  119. unsafeWindow.LINGOSPOT_DISABLED = true;
  120.  
  121. // THANKS to Descriptor for yet another way to block LingoSpot; doesn't on every page, unfortunately.
  122. // Still, it should reduce runtime for pages where it works.
  123. unsafeWindow.tf_maxKeywords = 0;
  124.  
  125. // Unfortunately, Linkworth has decided to remove their container div, so we're stuck crawling the entire document body. Meh.
  126. var links = document.evaluate("//a[@class='lw_cad_link' or @itxtdid]", document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  127. for (var i=0; i<links.snapshotLength; i++) {
  128. var anchor = links.snapshotItem(i);
  129. anchor.parentNode.replaceChild(document.createTextNode(anchor.textContent), anchor);
  130. }
  131. }, false);