forked from tshradheya/chrome-extension-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
32 lines (28 loc) · 969 Bytes
/
inject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This helps avoid conflicts in case we inject
// this script on the same page multiple times
// without reloading.
var injected = injected || (function(){
// An object that will contain the "methods"
// we can use from our event script.
var methods = {};
// This method will eventually return
// background colors from the current page.
methods.getBgColors = function(){
var nodes = document.querySelectorAll('*');
return nodes.length;
};
// This tells the script to listen for
// messages from our extension.
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
var data = {};
// If the method the extension has requested
// exists, call it and assign its response
// to data.
if (methods.hasOwnProperty(request.method))
data = methods[request.method]();
// Send the response back to our extension.
sendResponse({ data: data });
return true;
});
return true;
})();