From 703ea18bfd2cd19eb52582c2df3b07ef37d7a1a3 Mon Sep 17 00:00:00 2001 From: Mariam M Date: Fri, 31 Jul 2015 12:58:38 +0200 Subject: [PATCH] Include option to change Y/N User gets option to add a new value to Y/N on a single page/refresh so it gives them the extra functionality without interrupting their other web/reading experiences. --- content_script.js | 14 +++++++++++--- manifest.json | 4 +++- popup.html | 5 +++++ popup.js | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) 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;

Enter the name here:

+

Is the author not using Y/N? +

Enter the expression the author's using instead:

+

(Make sure you already entered a name above. This change will go away if you refresh, so you'll have to enter it again)

+

+

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. 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()); } +