Permalink
Please sign in to comment.
Showing
with
26 additions
and 32 deletions.
- BIN Mata.crx
- +24 −26 content.js
- +0 −4 jquery-2.1.4.min.js
- +2 −2 manifest.json
50
content.js
| @@ -1,39 +1,37 @@ | ||
| -var hidden_icon_name_html = "<input type='hidden' value='mata-inactive-38.png' id='mata-icon-name' />"; | ||
| +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").append(hidden_icon_name_html); | ||
| +body.appendChild(icon); | ||
| function activate_mata() { | ||
| - $("body").addClass("mata-friendly"); | ||
| + body.classList.add('mata-friendly'); | ||
| + icon.value = 'mata-active-38.png'; | ||
| + isActive = true; | ||
| } | ||
| function deactivate_mata() { | ||
| - $("body").removeClass("mata-friendly"); | ||
| + body.classList.remove('mata-friendly'); | ||
| + icon.value = 'mata-inactive-38.png'; | ||
| + isActive = false; | ||
| } | ||
| -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | ||
| - // Extension is clicked | ||
| - if (request.message == "clicked_browser_action") { | ||
| - // Change the extension's icon name on hidden field | ||
| - if ($("#mata-icon-name").val() == "mata-inactive-38.png") { | ||
| - $("#mata-icon-name").val("mata-active-38.png"); | ||
| - | ||
| - // Activate the mata | ||
| - activate_mata(); | ||
| - } else { | ||
| - $("#mata-icon-name").val("mata-inactive-38.png"); | ||
| - | ||
| - // Deactivate the mata | ||
| - deactivate_mata(); | ||
| - } | ||
| - | ||
| - chrome.runtime.sendMessage({ "message": "clicked_browser_action", "current_icon_path": $("#mata-icon-name").val() }); | ||
| - } | ||
| -}); | ||
| - | ||
| -$("body").bind("DOMSubtreeModified", function() { | ||
| - if ($("#mata-icon-name").val() == "mata-inactive-38.png") { | ||
| +function toggle_mata() { | ||
| + if (isActive) { | ||
| deactivate_mata(); | ||
| } else { | ||
| activate_mata(); | ||
| } | ||
| +} | ||
| + | ||
| +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", toggle_mata); |
0 comments on commit
7a7bd40