forked from wilbertliu/Mata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
41 lines (34 loc) · 1001 Bytes
/
content.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
39
40
41
var body = document.body;
var isActive = false;
var icon = document.createElement('input');
icon.type = 'hidden';
icon.value = 'meta-inactive-38.png';
icon.id = 'mata-icon-name';
body.appendChild(icon);
function activate_mata() {
body.classList.add('mata-friendly');
icon.value = 'mata-active-38.png';
isActive = true;
}
function deactivate_mata() {
body.classList.remove('mata-friendly');
icon.value = 'mata-inactive-38.png';
isActive = false;
}
function toggle_mata() {
if (isActive) {
deactivate_mata();
} else {
activate_mata();
}
}
function updateStatus() {
isActive = icon.value === 'meta-inactive-38.png' ? false : true;
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.message == "clicked_browser_action") {
toggle_mata();
chrome.runtime.sendMessage({ "message": "clicked_browser_action", "current_icon_path": icon.value });
}
});
body.addEventListener("DOMSubtreeModified", updateStatus);