Remove mutationObserver
This commit is contained in:
		
							parent
							
								
									b0be378fb1
								
							
						
					
					
						commit
						ee4b5ed5e8
					
				|  | @ -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 valChange = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig; | ||||||
| var person; | var person; | ||||||
| var replaceAll = function (){ | var replaceAll = function (){ | ||||||
| 	chrome.storage.local.get(null, function(items){ | 	chrome.storage.local.get(null, function(items){ | ||||||
| 		for(var key in items){ | 		if(items[DISABLE_KEY] !== true){ | ||||||
| 			if(items[key]){ | 			for(var key in items){ | ||||||
| 				if(key=="person") | 				if(items[key]){ | ||||||
| 					loadReplace(valChange, items[key]); | 					if(key=="person") | ||||||
| 				else{ | 						loadReplace(valChange, items[key]); | ||||||
| 					var s = escapeRegExp(key); | 					else if(key !== DISABLE_KEY){ | ||||||
| 					var temp = new RegExp(s, "ig"); | 						var s = escapeRegExp(key); | ||||||
| 					loadReplace(temp, items[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){ | 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 s = escapeRegExp(message.stuff); | ||||||
|   var val = new RegExp(s, "ig"); |   var val = new RegExp(s, "ig"); | ||||||
|   if(message.isYN) |   if(message.isYN) | ||||||
|  | @ -35,8 +38,12 @@ chrome.extension.onMessage.addListener(function(message,sender,sendResponse){ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| function loadReplace(rep, p){ | function loadReplace(rep, p){ | ||||||
| 	if(p!=null) | 	chrome.storage.local.get(DISABLE_KEY, function(obj){ | ||||||
| 		walk(document.body, rep, p); | 		var enabled = obj[DISABLE_KEY] !== true; | ||||||
|  | 		if(p!=null && enabled){ | ||||||
|  | 			walk(document.body, rep, p); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function walk(node, v, p){ | function walk(node, v, p){ | ||||||
|  | @ -66,20 +73,4 @@ function handleText(textNode, val, p){ | ||||||
| 	textNode.nodeValue = v; | 	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(); | replaceAll(); | ||||||
|  | @ -3,7 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| 	"manifest_version": 2, | 	"manifest_version": 2, | ||||||
| 	"name": "InteractiveFics", | 	"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.", | 	"description": "Replaces Y/N & other variables in Reader Insert/second person fics with words of your choice.", | ||||||
| 	"browser_action": { | 	"browser_action": { | ||||||
| 	"default_icon": "icon.png", | 	"default_icon": "icon.png", | ||||||
|  |  | ||||||
							
								
								
									
										20
									
								
								popup.html
								
								
								
								
							
							
						
						
									
										20
									
								
								popup.html
								
								
								
								
							|  | @ -34,10 +34,23 @@ label *:not([type="checkbox"]){ | ||||||
| .otherWords .change{ | .otherWords .change{ | ||||||
| 	margin-right:0; | 	margin-right:0; | ||||||
| } | } | ||||||
| #clear-name{ | #clear-name, #deactivate{ | ||||||
| 	margin-top:0.5em; | 	margin-top:0.5em; | ||||||
| 	width:96%; | 	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"]{ | input[type="text"]{ | ||||||
| 	width:70%; | 	width:70%; | ||||||
| } | } | ||||||
|  | @ -62,7 +75,7 @@ input[type="text"]{ | ||||||
| <body> | <body> | ||||||
| <h1>Enter the name here:</h1> | <h1>Enter the name here:</h1> | ||||||
| <form><input type="text" id="inputTxt"/><input type="submit" id="submit" value="Change"/></form> | <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><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> | 	<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> | <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> | <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> | </details> | ||||||
|  | <br> | ||||||
|  | 	<input type="button" id="deactivate"/> | ||||||
|  | </br> | ||||||
| <br> | <br> | ||||||
| <a href="http://interactivefics.tumblr.com/ask" target="_blank">Feedback, suggestions and requests.</a></br> | <a href="http://interactivefics.tumblr.com/ask" target="_blank">Feedback, suggestions and requests.</a></br> | ||||||
| </p> | </p> | ||||||
|  |  | ||||||
							
								
								
									
										72
									
								
								popup.js
								
								
								
								
							
							
						
						
									
										72
									
								
								popup.js
								
								
								
								
							|  | @ -1,28 +1,66 @@ | ||||||
| 
 | 
 | ||||||
|  | DISABLE_KEY = 'deactivate-this-extension-pls-interactive-fics-yalla-bina'; | ||||||
| document.addEventListener('DOMContentLoaded', function () { | 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('submit').addEventListener('click', clickHandler); | ||||||
|   document.getElementById('show-saved').addEventListener('click', function(){ |   document.getElementById('show-saved').addEventListener('click', function(){ | ||||||
| 	chrome.storage.local.get(null, function(items){ | 	chrome.storage.local.get(null, function(items){ | ||||||
| 		var list = document.getElementById('theList'); | 		var list = document.getElementById('theList'); | ||||||
| 		list.innerHTML = ""; | 		list.innerHTML = ""; | ||||||
| 		for(var key in items){ | 		for(var key in items){ | ||||||
| 			var k; | 			if(key !== DISABLE_KEY){ | ||||||
| 			if(key=="person") | 				var k; | ||||||
| 				k = "Y/N"; | 				if(key=="person") | ||||||
| 			else | 					k = "Y/N"; | ||||||
| 				k = key; | 				else | ||||||
| 			var v = items[key]; | 					k = key; | ||||||
| 			var rep = k + " -> " + v; | 				var v = items[key]; | ||||||
| 			var text = document.createTextNode(rep); | 				var rep = k + " -> " + v; | ||||||
| 			var node = document.createElement("LI"); | 				var text = document.createTextNode(rep); | ||||||
| 			node.appendChild(text); | 				var node = document.createElement("LI"); | ||||||
| 			node.id = key; | 				node.appendChild(text); | ||||||
| 			node.className = 'one-saved-item'; | 				node.id = key; | ||||||
| 			node.addEventListener('click', function(){ | 				node.className = 'one-saved-item'; | ||||||
| 				chrome.storage.local.remove(this.id); | 				node.addEventListener('click', function(){ | ||||||
| 				this.className+=' strikethrough'; | 					chrome.storage.local.remove(this.id); | ||||||
| 			}); | 					this.className+=' strikethrough'; | ||||||
| 			list.appendChild(node); | 				}); | ||||||
|  | 				list.appendChild(node); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Mariam Maarouf
						Mariam Maarouf