Permalink
Browse files

Remove jquery as dependency and refactor the code

  • Loading branch information...
1 parent 90c6b5a commit 7a7bd40a60e9dd53bbc182bc514e60fd2a2e93f0 @luruke luruke committed May 18, 2015
Showing with 26 additions and 32 deletions.
  1. BIN Mata.crx
  2. +24 −26 content.js
  3. +0 −4 jquery-2.1.4.min.js
  4. +2 −2 manifest.json
View
BIN Mata.crx
Binary file not shown.
View
@@ -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);
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -3,7 +3,7 @@
"name": "Mata",
"description": "Reading the web should be friendly for your eyes",
- "version": "1.0.0",
+ "version": "1.1.0",
"icons": {
"16": "mata-inactive-16.png",
@@ -25,7 +25,7 @@
"<all_urls>"
],
"css": ["content.css"],
- "js": ["jquery-2.1.4.min.js", "content.js"]
+ "js": ["content.js"]
}
]
}

0 comments on commit 7a7bd40

Please sign in to comment.