From ee4b5ed5e8c167d6a07226625bd0821c4e50f0c7 Mon Sep 17 00:00:00 2001 From: Mariam Maarouf Date: Fri, 19 May 2017 18:13:06 +0200 Subject: [PATCH] Remove mutationObserver --- content_script.js | 45 ++++++++++++----------------- manifest.json | 2 +- popup.html | 20 +++++++++++-- popup.js | 72 ++++++++++++++++++++++++++++++++++++----------- 4 files changed, 92 insertions(+), 47 deletions(-) diff --git a/content_script.js b/content_script.js index e820b1a..3c8052e 100644 --- a/content_script.js +++ b/content_script.js @@ -1,15 +1,19 @@ +DISABLE_KEY = 'deactivate-this-extension-pls-interactive-fics-yalla-bina'; + var valChange = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig; var person; var replaceAll = function (){ chrome.storage.local.get(null, function(items){ - for(var key in items){ - if(items[key]){ - if(key=="person") - loadReplace(valChange, items[key]); - else{ - var s = escapeRegExp(key); - var temp = new RegExp(s, "ig"); - loadReplace(temp, items[key]); + if(items[DISABLE_KEY] !== true){ + for(var key in items){ + if(items[key]){ + if(key=="person") + loadReplace(valChange, items[key]); + else if(key !== DISABLE_KEY){ + var s = escapeRegExp(key); + var temp = new RegExp(s, "ig"); + loadReplace(temp, items[key]); + } } } } @@ -22,7 +26,6 @@ function escapeRegExp(str) { } chrome.extension.onMessage.addListener(function(message,sender,sendResponse){ - //This is where the stuff you want from the background page will be var s = escapeRegExp(message.stuff); var val = new RegExp(s, "ig"); if(message.isYN) @@ -35,8 +38,12 @@ chrome.extension.onMessage.addListener(function(message,sender,sendResponse){ function loadReplace(rep, p){ - if(p!=null) - walk(document.body, rep, p); + chrome.storage.local.get(DISABLE_KEY, function(obj){ + var enabled = obj[DISABLE_KEY] !== true; + if(p!=null && enabled){ + walk(document.body, rep, p); + } + }); } function walk(node, v, p){ @@ -66,20 +73,4 @@ function handleText(textNode, val, p){ textNode.nodeValue = v; } -MutationObserver = window.MutationObserver || window.WebKitMutationObserver; - -var observer = new MutationObserver(function(mutations, observer) { - replaceAll(); -}); - -// define what element should be observed by the observer -// and what types of mutations trigger the callback -observer.observe(document, { - subtree: true, - childList: true - //... -}); - -//main - replaceAll(); \ No newline at end of file diff --git a/manifest.json b/manifest.json index 1ac58a1..c6b5fa4 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "manifest_version": 2, "name": "InteractiveFics", - "version": "4.2", + "version": "4.4", "description": "Replaces Y/N & other variables in Reader Insert/second person fics with words of your choice.", "browser_action": { "default_icon": "icon.png", diff --git a/popup.html b/popup.html index d201560..5ce1012 100644 --- a/popup.html +++ b/popup.html @@ -34,10 +34,23 @@ label *:not([type="checkbox"]){ .otherWords .change{ margin-right:0; } -#clear-name{ +#clear-name, #deactivate{ margin-top:0.5em; width:96%; } +#deactivate{ + background-color: #9b59b6; + color:white; + border:0px; + border-radius:0.5em; + transition-duration: 0.5s; +} +#deactivate:hover{ + color: #9b59b6; + background-color: white; + cursor:pointer; +} + input[type="text"]{ width:70%; } @@ -62,7 +75,7 @@ input[type="text"]{

Enter the name here:

- +

Need to replace something other than Y/N?

(This change will go away when you refresh/go to another page unless you check the box next to "Store this replacement")

@@ -89,6 +102,9 @@ input[type="text"]{
About Interactive Fics is a free Chrome extension developed by blaringsilence to improve your online story reading experience. The extension is open source and all source code can be found here.
+
+ +

Feedback, suggestions and requests.

diff --git a/popup.js b/popup.js index 616055b..28012bd 100644 --- a/popup.js +++ b/popup.js @@ -1,28 +1,66 @@ +DISABLE_KEY = 'deactivate-this-extension-pls-interactive-fics-yalla-bina'; document.addEventListener('DOMContentLoaded', function () { + + chrome.storage.local.get(DISABLE_KEY, function(obj){ + var isDeactivated = obj[DISABLE_KEY] !== true ? false : true; + var key = isDeactivated ? 'Re-activate ' : 'Deactivate '; + document.getElementById('deactivate').value = key + 'Extension'; + if(isDeactivated){ + document.getElementsByTagName("BODY")[0].title = "Extension is disabled"; + var elements = document.getElementsByTagName("INPUT"); + for(var i=0; i " + v; - var text = document.createTextNode(rep); - var node = document.createElement("LI"); - node.appendChild(text); - node.id = key; - node.className = 'one-saved-item'; - node.addEventListener('click', function(){ - chrome.storage.local.remove(this.id); - this.className+=' strikethrough'; - }); - list.appendChild(node); + if(key !== DISABLE_KEY){ + var k; + if(key=="person") + k = "Y/N"; + else + k = key; + var v = items[key]; + var rep = k + " -> " + v; + var text = document.createTextNode(rep); + var node = document.createElement("LI"); + node.appendChild(text); + node.id = key; + node.className = 'one-saved-item'; + node.addEventListener('click', function(){ + chrome.storage.local.remove(this.id); + this.className+=' strikethrough'; + }); + list.appendChild(node); + } } }); });