Disabling ANNOYING in-text ad links

Forums » General Opera topics » User JavaScript

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

22. May 2010, 20:32:46

Ansury

Posts: 69

Disabling ANNOYING in-text ad links

Just thought I'd share this gem in case others aren't aware of it yet, because I was amazed that this intended for FireFox-koolaid-drinking-users script works for me in Opera too (at least for Kontera scumware ads). Would it be wrong to 'cross-link' this thread in a more popular forum just because I'm so excited these rubbish ads are GONE? =)

I CAN'T STAND those double-underlined links that pop up STUPID ads every time you (accidentally) mouse-over on them. Whoever thought of and implemented that idea should go jump off a high cliff! That said:

http://userscripts.org/scripts/show/3637

In Opera 10.53 this worked when I defined a "User JavaScript Folder" under
O->Settings->Preferences->Advanced->Content->Javascript Options
and created a file named "disableTextAds.js" in the folder with this in it:

Script (for convenience or in case this link ever dies...):
// ==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);

23. May 2010, 16:06:04

Moderator

Tamil

:-(|)

Posts: 115322

You can block ads by adding those sites to content blocker.

28. May 2010, 13:57:39

SunlitMonkey

Posts: 1

Thanks Ansury! I dislike those ads as well and you offered a fast and easy solution. Cheers!

2. June 2010, 04:25:26

bingobax

Posts: 1

Opera 10.53 here. I tried this javascript idea, following your instructions to the letter. It doesn't work at all. I made sure javascript was enabled of course, restarted Opera, etc. I also have Cache set to empty automatically at shutdown, and Delete New Cookies On Exit.

As for Content Blocker, how do you add these sites to Content Blocker? The usual method doesn't work on these text ads. I have actually tried putting them in manually; that doesn't work either.

Anyone else?

21. June 2010, 03:05:08

xErath

javascript guru

Posts: 6588

Originally posted by bingobax:

As for Content Blocker, how do you add these sites to Content Blocker?



Add the following to the content blocker:

http://*.intellitxt.com/*
http://*.adbrite.com/*
http://*.text-link-ads.com/*
http://kona.kontera.com/javascript/lib/KonaLibInline.js
http://resources.infolinks.com/*

Should stop most of them.
For a collection of user scripts visit
http://my.opera.com/xErath/blog/

Forums » General Opera topics » User JavaScript