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

Unified Diff: include.preload.js

Issue 11627039: Added ad counting functionality (Closed)
Patch Set: Created Sept. 18, 2013, 10:07 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « background.js ('k') | lib/prefs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -19,6 +19,14 @@
var elemhideElt = null;
+// onRequest and sendRequest are deprecated as of Chrome 20
+var ChromeCompat = {
+ runtime: {
+ onMessage: ("runtime" in chrome) ? chrome.runtime.onMessage : chrome.extension.onRequest,
+ sendMessage: ("runtime" in chrome) ? chrome.runtime.sendMessage : chrome.extension.sendRequest
+ }
+};
+
// Sets the currently used CSS rules for elemhide filters
function setElemhideCSSRules(selectors)
{
@@ -101,11 +109,32 @@
document.addEventListener("error", checkCollapse, true);
document.addEventListener("load", checkCollapse, true);
-
+
chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameUrl: window.location.href}, function(response)
{
setElemhideCSSRules(response.selectors);
});
+
+ // Make sure to only count stats in top level frame
+ if (window.top !== window)
+ return;
+
+ var stats = {
+ blocked: 0
+ };
+ ChromeCompat.runtime.onMessage.addListener(function(request, sender, sendResponse)
+ {
+ switch (request.reqtype)
+ {
+ case "get-stats":
+ sendResponse(stats);
+ break;
+ case "update-stats":
+ if (request.blocked)
+ stats.blocked++;
+ break;
+ }
+ });
}
// In Chrome 18 the document might not be initialized yet
« no previous file with comments | « background.js ('k') | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld