forked from googlearchive/polymer-devtools-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
38 lines (34 loc) · 1.1 KB
/
contentScript.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
33
34
35
36
37
38
/**
* adds the extension ID to the event name so it's unique and matches with what
* the host page fires.
* @param {String} name event name
* @return {String} new event name
*/
function getNamespacedEventName(name) {
return chrome.runtime.id + '-' + name;
}
window.addEventListener(getNamespacedEventName('object-changed'), function(event) {
chrome.runtime.sendMessage({
name: 'object-changed',
changeList: event.detail
});
});
window.addEventListener(getNamespacedEventName('dom-mutation'), function(event) {
chrome.runtime.sendMessage({
name: 'dom-mutation',
changeList: event.detail
});
});
window.addEventListener(getNamespacedEventName('inspected-element-changed'), function(event) {
chrome.runtime.sendMessage({
name: 'inspected-element-changed',
key: event.detail.key
});
});
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
// When panel closes, background page will tell content script to tell the host
// page to do some clean-up
if (message.name === 'clean-up') {
window.dispatchEvent(new CustomEvent('clean-up'));
}
});