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

Side by Side Diff: include.preload.js

Issue 11627039: Added ad counting functionality (Closed)
Patch Set: Created Sept. 11, 2013, 3:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var SELECTOR_GROUP_SIZE = 20; 18 var SELECTOR_GROUP_SIZE = 20;
19 19
20 var elemhideElt = null; 20 var elemhideElt = null;
21 21
22 // onRequest and sendRequest are deprecated as of Chrome 20
23 var ChromeCompat = {
24 runtime: {
25 onMessage: ("runtime" in chrome) ? chrome.runtime.onMessage : chrome.extensi on.onRequest,
26 sendMessage: ("runtime" in chrome) ? chrome.runtime.sendMessage : chrome.ext ension.sendRequest
27 }
28 };
29
22 // Sets the currently used CSS rules for elemhide filters 30 // Sets the currently used CSS rules for elemhide filters
23 function setElemhideCSSRules(selectors) 31 function setElemhideCSSRules(selectors)
24 { 32 {
25 if (elemhideElt && elemhideElt.parentNode) 33 if (elemhideElt && elemhideElt.parentNode)
26 elemhideElt.parentNode.removeChild(elemhideElt); 34 elemhideElt.parentNode.removeChild(elemhideElt);
27 35
28 if (!selectors) 36 if (!selectors)
29 return; 37 return;
30 38
31 elemhideElt = document.createElement("style"); 39 elemhideElt = document.createElement("style");
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 102 }
95 103
96 function init() 104 function init()
97 { 105 {
98 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything 106 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything
99 if (!(document.documentElement instanceof HTMLElement)) 107 if (!(document.documentElement instanceof HTMLElement))
100 return; 108 return;
101 109
102 document.addEventListener("error", checkCollapse, true); 110 document.addEventListener("error", checkCollapse, true);
103 document.addEventListener("load", checkCollapse, true); 111 document.addEventListener("load", checkCollapse, true);
104 112
105 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response) 113 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response)
106 { 114 {
107 setElemhideCSSRules(response.selectors); 115 setElemhideCSSRules(response.selectors);
108 }); 116 });
117
118 // Make sure to only count stats in top level frame
119 if (window.top !== window)
120 return;
121
122 var stats = {
123 blocked: 0
124 };
Wladimir Palant 2013/09/18 09:44:41 Seeing that the content script is merely used to s
125 ChromeCompat.runtime.onMessage.addListener(function(request, sender, sendRespo nse)
126 {
127 switch (request.reqtype)
128 {
129 case "get-stats":
130 sendResponse(stats);
131 break;
132 case "update-stats":
133 if (request.blocked)
134 stats.blocked++;
135 break;
136 }
137 });
109 } 138 }
110 139
111 // In Chrome 18 the document might not be initialized yet 140 // In Chrome 18 the document might not be initialized yet
112 if (document.documentElement) 141 if (document.documentElement)
113 init(); 142 init();
114 else 143 else
115 window.setTimeout(init, 0); 144 window.setTimeout(init, 0);
OLDNEW

Powered by Google App Engine
This is Rietveld