diff --git a/content_script.js b/content_script.js index 237479c..f6f2660 100644 --- a/content_script.js +++ b/content_script.js @@ -1,3 +1,11 @@ +var valChange = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig; + +chrome.extension.onMessage.addListener(function(message,sender,sendResponse){ + //This is where the stuff you want from the background page will be + valChange = new RegExp(message.stuff, "ig"); + loadReplace(); +}); + var person; loadReplace(); @@ -42,8 +50,8 @@ function walk(node) function handleText(textNode) { - var v = textNode.nodeValue; - v = v.replace(/\by\/n\b/ig, person); + var v = textNode.nodeValue; + v = v.replace(valChange, person); //replaces Y/N or other value entered regardless of the case, whether it's in a bracket or not textNode.nodeValue = v; } @@ -60,4 +68,4 @@ observer.observe(document, { subtree: true, childList: true //... -}); \ No newline at end of file +}); diff --git a/manifest.json b/manifest.json index dd97b06..566d836 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,9 @@ { +"update_url": "https://clients2.google.com/service/update2/crx", + "manifest_version": 2, "name": "InteractiveFics", - "version": "1.0.2", + "version": "3.0", "description": "Replaces Y/N in Reader Insert/second person fics with a name of your choice.", "browser_action": { "default_icon": "icon.png", diff --git a/popup.html b/popup.html index 596508f..0b5a335 100644 --- a/popup.html +++ b/popup.html @@ -29,6 +29,11 @@ color: #16a085; <body> <h1>Enter the name here:</h1> <form><input type="text" id="inputTxt" placeholder="To restore, enter 'Y/N'"/><input type="submit" id="submit" value="Change"/></form> +<p><details><summary>Is the author not using Y/N?</summary> + <p>Enter the expression the author's using instead:</p> + <p><small>(Make sure you already entered a name above. This change will go away if you refresh, so you'll have to enter it again)</small></p> + <p><form><input type="text" id="other"><input type="submit" id="change" value="Enter"></form></p> +</details></p> <p> <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> diff --git a/popup.js b/popup.js index e7d4002..9fd4e11 100644 --- a/popup.js +++ b/popup.js @@ -3,7 +3,21 @@ document.addEventListener('DOMContentLoaded', function () { document.getElementById("submit").addEventListener('click', clickHandler); }); //instead of onclick="clickHandler()" in popup.html +document.addEventListener('DOMContentLoaded', function(){ + document.getElementById("change").addEventListener('click', otherHandler); +}); //instead of onclick="otherHandler()" in popup.html +function otherHandler(){ + var myInput = document.getElementById("other").value; + var valChange = escapeRegExp(myInput); + chrome.tabs.query({active:true,currentWindow:true}, function(tab) { + chrome.tabs.sendMessage(tab[0].id, {stuff:valChange}); +}); +} + +function escapeRegExp(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); +} function clickHandler(){ @@ -11,3 +25,4 @@ var person = document.getElementById("inputTxt").value; chrome.storage.local.set({"person": person}, chrome.tabs.reload()); } +