Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include.textads.js

Issue 8787016: Remove "disable inline text-ads" feature (Closed)
Patch Set: Created Nov. 6, 2012, 7:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« background.js ('K') | « background.js ('k') | manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of the Adblock Plus extension,
3 * Copyright (C) 2006-2012 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 // Explicitly removes inline text ads, in case we were unable to block the ad sc ript itself
19 // in the beforeload handler.
20 function removeTextAdFromElement(elt) {
21 // The DOMNodeInserted hooks means we get called for #text nodes, which means localName is null.
22 // We don't touch those
23 if(!elt.localName) return;
24 var keepNode;
25 switch(elt.localName.toUpperCase()) {
26 // AdBrite
27 case 'ISPAN':
28 if(elt.id.indexOf('AdBriteInlineAd_') >= 0) {
29 keepNode = document.createTextNode(elt.id.substr('AdBriteInlineAd_'.leng th));
30 }
31 break;
32
33 // Chitika and InfoLinks
34 case 'SPAN':
35 var fc = elt.firstChild;
36 if(!fc) break;
37 if(elt.className == 'IL_AD') {
38 keepNode = fc;
39 } else if(fc.localName && fc.localName.toUpperCase() == 'A' && fc.classNam e.indexOf('lx-link') >= 0) {
40 keepNode = fc.firstChild;
41 }
42 break;
43
44 // EchoTopic and ResultLinks
45 case 'NOBR':
46 var fc = elt.firstChild;
47 if(fc && fc.nodeName != '#text' && (fc.className == 'tfTextLink' || fc.id. indexOf('RLLINK') >= 0)) {
48 keepNode = fc.firstChild;
49 }
50 break;
51
52 case 'A':
53 // Some other ones, including LinkWorth, Kontera, Affinity
54 switch(elt.className) {
55 case 'IL_LINK_STYLE':
56 case 'contextual':
57 case 'lw_cad_link':
58 case 'cm_word':
59 keepNode = elt.firstChild;
60 break;
61
62 // Kontera really mangles the original text
63 case 'kLink':
64 var textNodes = elt.querySelectorAll('font > span'), text = "";
65 for(var i = 0; i < textNodes.length; i++) text += textNodes[i].innerHT ML;
66 keepNode = document.createTextNode(text);
67 break;
68
69 default:
70 // IntelliTxt
71 if(elt.hasAttribute('itxtdid')) {
72 keepNode = elt.firstChild;
73 break;
74 }
75
76 // Not sure if this AdBrite check is still necessary
77 if(elt.id.indexOf('AdBriteInlineAd_') >= 0) {
78 keepNode = document.createTextNode(elt.id.substr('AdBriteInlineAd_'. length));
79 break;
80 }
81 }
82 break; // case 'A'
83 }
84
85 // Replace the offending node with the original content that was inside it
86 if(keepNode) elt.parentNode.replaceChild(keepNode, elt);
87 }
88
89 chrome.extension.sendRequest({reqtype: "get-domain-enabled-state"}, function(res ponse) {
90 if(response.enabled && response.disableInlineTextAds) {
91 // Listen for inserted nodes and process them as they come in
92 var observer = new WebKitMutationObserver(function(mutations)
93 {
94 for (var i = 0; i < mutations.length; i++)
95 for (var j = 0; j < mutations[i].addedNodes.length; j++)
96 removeTextAdFromElement(mutations[i].addedNodes[j]);
97 });
98 observer.observe(document.documentElement, {subtree: true, childList: true}) ;
99
100 // However, our event handler above may not have been inserted in time, so w e also scan the document.
101 // We use setTimeout here because there is no way to ensure that we are runn ing after the ad scripts have run.
102 // So we hope that the delay is long enough.
103 setTimeout(function() {
104 var elts = document.querySelectorAll("a.IL_LINK_STYLE, a.lw_cad_link, a.cm _word, a.contextual, a.kLink, a[itxtdid], nobr, ispan, span.IL_AD");
105 for (var i=0; i<elts.length; i++) removeTextAdFromElement(elts[i]);
106 }, 50);
107 }
108 });
OLDNEW
« background.js ('K') | « background.js ('k') | manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld