diff --git a/content_script.js b/content_script.js index 3c8052e..29649b8 100644 --- a/content_script.js +++ b/content_script.js @@ -1,49 +1,44 @@ -DISABLE_KEY = 'deactivate-this-extension-pls-interactive-fics-yalla-bina'; +DEACTIVATE_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 if(key !== DISABLE_KEY){ - var s = escapeRegExp(key); - var temp = new RegExp(s, "ig"); - loadReplace(temp, items[key]); - } +chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { + escapeAndReplace(message.input_word, message.replace_value) +}); + +const replaceAll = () => { + chrome.storage.local.get(null, items => { + if (!items[DEACTIVATE_KEY]) { + for (var key in itmes) { + if (key == 'person') { + const regexp_y_n = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig + replace(regexp_y_n, items[key]) + } else if (key !== DEACTIVATE_KEY) { + escapeAndReplace(key, items[key]) } } } - }); + }) } - -function escapeRegExp(str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); +const escapeAndReplace = (input_word, replace_value) => { + const input_word_escaped = escapeRegExp(input_word) + const regexp_input_word = new RegExp(input_word_escaped, "ig") + replace(regexp_input_word, replace_value) } -chrome.extension.onMessage.addListener(function(message,sender,sendResponse){ - var s = escapeRegExp(message.stuff); - var val = new RegExp(s, "ig"); - if(message.isYN) - loadReplace(val, person); - else - if(message.replaceVal){ - loadReplace(val, message.replaceVal); - } -}); +const escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") - -function loadReplace(rep, p){ - chrome.storage.local.get(DISABLE_KEY, function(obj){ - var enabled = obj[DISABLE_KEY] !== true; - if(p!=null && enabled){ - walk(document.body, rep, p); +const replace = (input_word, replace_value) => { + chrome.storage.local.get(DEACTIVATE_KEY, obj => { + if (replace_value && !obj[DEACTIVATE_KEY]) { + walk(document.body, input_word, replace_value) } - }); + }) +} + +const replaceText = (textNode, input_word, replace_value) => { + const node_value = textNode.nodeValue + node_value = node_value.replace(input_word, replace_value) + textNode.nodeValue = node_value } function walk(node, v, p){ @@ -62,15 +57,9 @@ function walk(node, v, p){ } break; case 3: // Text node - handleText(node, v, p); + replaceText(node, v, p); break; } } -function handleText(textNode, val, p){ - var v = textNode.nodeValue; - v = v.replace(val, p); //replaces Y/N or other value entered regardless of the case, whether it's in a bracket or not - textNode.nodeValue = v; -} - -replaceAll(); \ No newline at end of file +replaceAll() diff --git a/manifest.json b/manifest.json index c6b5fa4..21cc8b9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,32 +1,38 @@ { -"update_url": "https://clients2.google.com/service/update2/crx", - - "manifest_version": 2, - "name": "InteractiveFics", - "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", - "default_popup": "popup.html" }, + "update_url": "https://clients2.google.com/service/update2/crx", + "manifest_version": 2, + "name": "InteractiveFics", + "author": "mariamrf", + "version": "5.0", + "description": "Replaces Y/N & other variables in Reader Insert/second person fics with words of your choice.", + "browser_action": { + "default_title": "InteractiveFics", + "default_icon": "icon.png", + "default_popup": "popup.html" + }, "permissions": [ - "storage", - "tabs"], - "icons": { "16": "icon-16.png", - "48": "icon-48.png", - "128": "icon-128.png" }, - "content_scripts": - [ - { - - "js": ["content_script.js"], - "run_at": "document_end", - "matches": ["*://*/*"] - } - ], - "incognito": "split", - "background": { -"page": "popup.html" -} - -} - + "storage", + "tabs" + ], + "icons": { + "16": "icon-16.png", + "48": "icon-48.png", + "128": "icon-128.png" + }, + "content_scripts": [ + { + "js": [ + "content_script.js" + ], + "run_at": "document_idle", + "matches": [ + "*://*/*" + ] + } + ], + "incognito": "split", + "background": { + "page": "popup.html" + }, + "homepage_url": "https://interactivefics.tumblr.com" +} \ No newline at end of file diff --git a/popup.css b/popup.css new file mode 100644 index 0000000..c044727 --- /dev/null +++ b/popup.css @@ -0,0 +1,89 @@ +body { + background-color: white; + color: #2C3531; + width: 250px; + padding:10px; + font-family: 'Rubik', sans-serif; +} +h1 { + font-size: 16px; +} +a{ + color: #D9B08C; + transition-duration: 0.5s; +} +a:hover{ + color: #16a085; +} + +label *:not([type="checkbox"]){ + display:block; +} + +.other-words input:not([type="checkbox"]){ + margin-top:0.2em; + width:100%; +} +.other-words .other, .other-words .replaceBy{ + width:98%; +} +.other-words .change{ + margin-right:0; +} +#clear-name, #deactivate{ + margin-top:0.5em; + width:96%; +} +#deactivate{ + background-color: #116466; + color:white; + border:0px; + border-radius:0.5em; + transition-duration: 0.5s; + font-size: 1em; +} +#deactivate:hover{ + color: #116466; + background-color: white; + cursor:pointer; +} + +input[type="text"]{ + width:70%; +} +.strikethrough{ + text-decoration: line-through; +} +.one-saved-item:hover{ + background-color: #e74c3c; + color: white; + cursor: pointer; +} +.saved-items-list-wrapper{ + height:100px; + overflow: auto; +} + +details { + margin-top: 0.8em; +} + +summary { + cursor: pointer; +} + +input[type="button"]{ + margin-top: 0.8em; + margin-bottom: 0.8em; +} + +input[type="submit"]{ + cursor: pointer; + transition-duration: 0.5s; +} + +input[type="submit"]:hover { + background-color: #2C3531; + color: white; + border-radius: 0.4em; +} diff --git a/popup.html b/popup.html index 5ce1012..ba7e88e 100644 --- a/popup.html +++ b/popup.html @@ -1,116 +1,55 @@ -
- - - - - - -(This change will go away when you refresh/go to another page unless you check the box next to "Store this replacement")Need to replace something other than Y/N?
-