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.
This commit is contained in:
parent
36bde5aaa8
commit
703ea18bfd
|
@ -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
|
||||
//...
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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>
|
||||
|
|
15
popup.js
15
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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue