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 |