Remove mutationObserver
This commit is contained in:
parent
b0be378fb1
commit
ee4b5ed5e8
|
@ -1,18 +1,22 @@
|
|||
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){
|
||||
if(items[DISABLE_KEY] !== true){
|
||||
for(var key in items){
|
||||
if(items[key]){
|
||||
if(key=="person")
|
||||
loadReplace(valChange, items[key]);
|
||||
else{
|
||||
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)
|
||||
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();
|
|
@ -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",
|
||||
|
|
20
popup.html
20
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"]{
|
|||
<body>
|
||||
<h1>Enter the name here:</h1>
|
||||
<form><input type="text" id="inputTxt"/><input type="submit" id="submit" value="Change"/></form>
|
||||
<button id="clear-name">Clear Name</button>
|
||||
<input type="button" id="clear-name" value="Clear Name"/>
|
||||
<p><details id="moreWords"><summary>Need to replace something other than Y/N?</summary>
|
||||
<p><small>(This change will go away when you refresh/go to another page unless you check the box next to "Store this replacement")</small></p>
|
||||
|
||||
|
@ -89,6 +102,9 @@ input[type="text"]{
|
|||
<details><summary>About</summary>
|
||||
<a href="http://interactivefics.tumblr.com" target="_blank" title="Official tumblr">Interactive Fics</a> is a free Chrome extension developed by <a href="https://github.com/blaringsilence" target="_blank" title="her github">blaringsilence</a> to improve your online story reading experience. The extension is open source and all source code can be found <a href="https://github.com/blaringsilence/interactive-fics" title="github repo">here.</a>
|
||||
</details>
|
||||
<br>
|
||||
<input type="button" id="deactivate"/>
|
||||
</br>
|
||||
<br>
|
||||
<a href="http://interactivefics.tumblr.com/ask" target="_blank">Feedback, suggestions and requests.</a></br>
|
||||
</p>
|
||||
|
|
38
popup.js
38
popup.js
|
@ -1,11 +1,48 @@
|
|||
|
||||
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<elements.length; i++){
|
||||
if(elements[i].id !== 'deactivate')
|
||||
elements[i].disabled = 'disabled';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('deactivate').addEventListener('click', function(){
|
||||
chrome.storage.local.get(DISABLE_KEY, function(obj){
|
||||
// 1. previous state:
|
||||
var wasDeactivated = obj[DISABLE_KEY] === undefined ? false : true;
|
||||
// 2. button:
|
||||
var key = wasDeactivated ? 'Deactivate ' : 'Re-activate ';
|
||||
document.getElementById('deactivate').value = key + 'Extension';
|
||||
// 3. storage:
|
||||
if(wasDeactivated){
|
||||
chrome.storage.local.remove(DISABLE_KEY);
|
||||
}
|
||||
else{
|
||||
var obj = {};
|
||||
obj[DISABLE_KEY] = true;
|
||||
chrome.storage.local.set(obj);
|
||||
}
|
||||
chrome.tabs.reload();
|
||||
window.close();
|
||||
});
|
||||
});
|
||||
document.getElementById('submit').addEventListener('click', clickHandler);
|
||||
document.getElementById('show-saved').addEventListener('click', function(){
|
||||
chrome.storage.local.get(null, function(items){
|
||||
var list = document.getElementById('theList');
|
||||
list.innerHTML = "";
|
||||
for(var key in items){
|
||||
if(key !== DISABLE_KEY){
|
||||
var k;
|
||||
if(key=="person")
|
||||
k = "Y/N";
|
||||
|
@ -24,6 +61,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
});
|
||||
list.appendChild(node);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('clear-name').addEventListener('click', function(){ chrome.storage.local.remove("person", chrome.tabs.reload()) } );
|
||||
|
|
Loading…
Reference in New Issue