Cleanup
This commit is contained in:
parent
ee4b5ed5e8
commit
7dba8578ca
|
@ -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;
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
var person;
|
escapeAndReplace(message.input_word, message.replace_value)
|
||||||
var replaceAll = function (){
|
});
|
||||||
chrome.storage.local.get(null, function(items){
|
|
||||||
if(items[DISABLE_KEY] !== true){
|
const replaceAll = () => {
|
||||||
for(var key in items){
|
chrome.storage.local.get(null, items => {
|
||||||
if(items[key]){
|
if (!items[DEACTIVATE_KEY]) {
|
||||||
if(key=="person")
|
for (var key in itmes) {
|
||||||
loadReplace(valChange, items[key]);
|
if (key == 'person') {
|
||||||
else if(key !== DISABLE_KEY){
|
const regexp_y_n = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig
|
||||||
var s = escapeRegExp(key);
|
replace(regexp_y_n, items[key])
|
||||||
var temp = new RegExp(s, "ig");
|
} else if (key !== DEACTIVATE_KEY) {
|
||||||
loadReplace(temp, items[key]);
|
escapeAndReplace(key, items[key])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const escapeAndReplace = (input_word, replace_value) => {
|
||||||
function escapeRegExp(str) {
|
const input_word_escaped = escapeRegExp(input_word)
|
||||||
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
const regexp_input_word = new RegExp(input_word_escaped, "ig")
|
||||||
|
replace(regexp_input_word, replace_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.extension.onMessage.addListener(function(message,sender,sendResponse){
|
const escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")
|
||||||
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 replace = (input_word, replace_value) => {
|
||||||
function loadReplace(rep, p){
|
chrome.storage.local.get(DEACTIVATE_KEY, obj => {
|
||||||
chrome.storage.local.get(DISABLE_KEY, function(obj){
|
if (replace_value && !obj[DEACTIVATE_KEY]) {
|
||||||
var enabled = obj[DISABLE_KEY] !== true;
|
walk(document.body, input_word, replace_value)
|
||||||
if(p!=null && enabled){
|
|
||||||
walk(document.body, rep, p);
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
function walk(node, v, p){
|
||||||
|
@ -62,15 +57,9 @@ function walk(node, v, p){
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3: // Text node
|
case 3: // Text node
|
||||||
handleText(node, v, p);
|
replaceText(node, v, p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleText(textNode, val, p){
|
replaceAll()
|
||||||
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();
|
|
||||||
|
|
|
@ -1,32 +1,38 @@
|
||||||
{
|
{
|
||||||
"update_url": "https://clients2.google.com/service/update2/crx",
|
"update_url": "https://clients2.google.com/service/update2/crx",
|
||||||
|
"manifest_version": 2,
|
||||||
"manifest_version": 2,
|
"name": "InteractiveFics",
|
||||||
"name": "InteractiveFics",
|
"author": "mariamrf",
|
||||||
"version": "4.4",
|
"version": "5.0",
|
||||||
"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_title": "InteractiveFics",
|
||||||
"default_popup": "popup.html" },
|
"default_icon": "icon.png",
|
||||||
|
"default_popup": "popup.html"
|
||||||
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage",
|
"storage",
|
||||||
"tabs"],
|
"tabs"
|
||||||
"icons": { "16": "icon-16.png",
|
],
|
||||||
"48": "icon-48.png",
|
"icons": {
|
||||||
"128": "icon-128.png" },
|
"16": "icon-16.png",
|
||||||
"content_scripts":
|
"48": "icon-48.png",
|
||||||
[
|
"128": "icon-128.png"
|
||||||
{
|
},
|
||||||
|
"content_scripts": [
|
||||||
"js": ["content_script.js"],
|
{
|
||||||
"run_at": "document_end",
|
"js": [
|
||||||
"matches": ["*://*/*"]
|
"content_script.js"
|
||||||
}
|
],
|
||||||
],
|
"run_at": "document_idle",
|
||||||
"incognito": "split",
|
"matches": [
|
||||||
"background": {
|
"*://*/*"
|
||||||
"page": "popup.html"
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
}
|
"incognito": "split",
|
||||||
|
"background": {
|
||||||
|
"page": "popup.html"
|
||||||
|
},
|
||||||
|
"homepage_url": "https://interactivefics.tumblr.com"
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
161
popup.html
161
popup.html
|
@ -1,116 +1,55 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<link href='http://fonts.googleapis.com/css?family=Play' rel='stylesheet' type='text/css'>
|
<link href="https://fonts.googleapis.com/css?family=Rubik&display=swap" rel="stylesheet">
|
||||||
<style type="text/css">
|
<link href='popup.css' rel='stylesheet' type='text/css'>
|
||||||
body {
|
<script src="popup.js" type="text/javascript"></script>
|
||||||
background-color: white;
|
</head>
|
||||||
color: #16a085;
|
<body>
|
||||||
width: 250px;
|
<div id="all-but-deactivate-wrapper">
|
||||||
padding:10px;
|
<h1>Enter the name here:</h1>
|
||||||
font-family: 'Play', sans-serif;
|
<form id="change-name-form">
|
||||||
}
|
<input type="text" id="change-name-form-text"/>
|
||||||
h1 {
|
<input type="submit" value="Change"/>
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
a{
|
|
||||||
color: #e67e22;
|
|
||||||
}
|
|
||||||
a:hover{
|
|
||||||
color: #16a085;
|
|
||||||
}
|
|
||||||
|
|
||||||
label *:not([type="checkbox"]){
|
|
||||||
display:block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.otherWords input:not([type="checkbox"]){
|
|
||||||
margin-top:0.2em;
|
|
||||||
width:100%;
|
|
||||||
}
|
|
||||||
.otherWords .other, .otherWords .replaceBy{
|
|
||||||
width:98%;
|
|
||||||
}
|
|
||||||
.otherWords .change{
|
|
||||||
margin-right:0;
|
|
||||||
}
|
|
||||||
#clear-name, #deactivate{
|
|
||||||
margin-top:0.5em;
|
|
||||||
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"]{
|
|
||||||
width:70%;
|
|
||||||
}
|
|
||||||
.strikethrough{
|
|
||||||
text-decoration: line-through;
|
|
||||||
}
|
|
||||||
.one-saved-item:hover{
|
|
||||||
background-color: #e74c3c;
|
|
||||||
color: white;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.savedItemsList{
|
|
||||||
height:100px;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<script src="popup.js" type="text/javascript" >
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Enter the name here:</h1>
|
|
||||||
<form><input type="text" id="inputTxt"/><input type="submit" id="submit" value="Change"/></form>
|
|
||||||
<input type="button" id="clear-name" value="Clear Name"/>
|
|
||||||
<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><form class="otherWords changeForm">
|
|
||||||
<label><span>Value [e.g L/N, E/C, etc]:</span>
|
|
||||||
<input type="text" name="replaceWord" class="other"></label>
|
|
||||||
<br>
|
|
||||||
<label><span>Replace with:</span>
|
|
||||||
<input type="text" name="replaceWith" class="replaceBy"></label>
|
|
||||||
<label><input type="checkbox" name="isPerm">Store this replacement</label>
|
|
||||||
<input type="submit" class="change" value="Change">
|
|
||||||
</form>
|
</form>
|
||||||
</p>
|
<form id="clear-name-form">
|
||||||
</details></p>
|
<input type="submit" id="clear-name" value="Clear Name"/>
|
||||||
<p>
|
</form>
|
||||||
<p><details><summary id="show-saved">STORED REPLACEMENTS</summary>
|
<details>
|
||||||
<p>To remove, simply click on a replacement. To change, re-enter in the previous section.</p>
|
<summary>Need to replace something other than Y/N?</summary>
|
||||||
<div class="savedItemsList">
|
<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>
|
||||||
<ul id="theList">
|
<p>
|
||||||
</ul>
|
<form id="replace-other-words-form" class="other-words">
|
||||||
|
<label>
|
||||||
|
<span>Value (e.g. L/N, E/C, etc):</span>
|
||||||
|
<input type="text" id="replace-word" class="other"/>
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<label>
|
||||||
|
<span>Replace with:</span>
|
||||||
|
<input type="text" id="replace-with" class="replaceBy"/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="is-perm">Store this replacement
|
||||||
|
</label>
|
||||||
|
<input type="submit" class="change" value="Change">
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary id="show-saved">Stored Replacements</summary>
|
||||||
|
<p><small>To remove, simply click on a replacement. To change, re-enter in the previous section.</small></p>
|
||||||
|
<div class="saved-items-list-wrapper">
|
||||||
|
<ul id="saved-items-list">
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>About</summary>
|
||||||
|
<a href="http://interactivefics.tumblr.com" target="_blank" title="Official site">Interactive Fics</a> is a free Chrome extension built to improve your online story reading experience. The extension is open source and all source code can be found <a href="https://github.com/interactivefics/interactive-fics" target="_blank" title="github repo">here.</a>
|
||||||
|
</details>
|
||||||
</div>
|
</div>
|
||||||
</details></p>
|
<input type="button" id="deactivate"/>
|
||||||
<p>
|
<a href="http://interactivefics.tumblr.com/ask" target="_blank">Feedback, suggestions and requests.</a></br>
|
||||||
<details><summary>About</summary>
|
</body>
|
||||||
<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>
|
|
||||||
<br>
|
|
||||||
<input type="button" id="deactivate"/>
|
|
||||||
</br>
|
|
||||||
<br>
|
|
||||||
<a href="http://interactivefics.tumblr.com/ask" target="_blank">Feedback, suggestions and requests.</a></br>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
202
popup.js
202
popup.js
|
@ -1,108 +1,122 @@
|
||||||
|
DEACTIVATE_KEY = 'deactivate-this-extension-pls-interactive-fics-yalla-bina';
|
||||||
|
|
||||||
DISABLE_KEY = 'deactivate-this-extension-pls-interactive-fics-yalla-bina';
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
// event listeners
|
||||||
|
document.getElementById('change-name-form').addEventListener('submit', changeName)
|
||||||
|
document.getElementById('clear-name-form').addEventListener('submit', clearName)
|
||||||
|
document.getElementById('replace-other-words-form').addEventListener('submit', replaceOther)
|
||||||
|
document.getElementById('show-saved').addEventListener('click', loadSaved)
|
||||||
|
document.getElementById('deactivate').addEventListener('click', toggleDeactivate)
|
||||||
|
|
||||||
chrome.storage.local.get(DISABLE_KEY, function(obj){
|
// set disable/enable button
|
||||||
var isDeactivated = obj[DISABLE_KEY] !== true ? false : true;
|
setDeactivateKey()
|
||||||
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){
|
const changeName = () => {
|
||||||
// 1. previous state:
|
const person = document.getElementById('change-name-form-text').value
|
||||||
var wasDeactivated = obj[DISABLE_KEY] === undefined ? false : true;
|
if (person) {
|
||||||
// 2. button:
|
chrome.storage.local.set({'person': person}, chrome.tabs.reload())
|
||||||
var key = wasDeactivated ? 'Deactivate ' : 'Re-activate ';
|
}
|
||||||
document.getElementById('deactivate').value = key + 'Extension';
|
}
|
||||||
// 3. storage:
|
|
||||||
if(wasDeactivated){
|
const clearName = () => {
|
||||||
chrome.storage.local.remove(DISABLE_KEY);
|
chrome.storage.local.remove('person', chrome.tabs.reload())
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
var obj = {};
|
const replaceOther = () => {
|
||||||
obj[DISABLE_KEY] = true;
|
const input_word = document.getElementById('replace-word').value
|
||||||
chrome.storage.local.set(obj);
|
const replacement = document.getElementById('replace-with').value
|
||||||
}
|
if (input_word && replacement) {
|
||||||
chrome.tabs.reload();
|
if (document.getElementById('is-perm').checked) {
|
||||||
window.close();
|
const obj = {}
|
||||||
});
|
obj[input_word] = replacement
|
||||||
});
|
chrome.storage.local.set(obj)
|
||||||
document.getElementById('submit').addEventListener('click', clickHandler);
|
}
|
||||||
document.getElementById('show-saved').addEventListener('click', function(){
|
|
||||||
chrome.storage.local.get(null, function(items){
|
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
|
||||||
var list = document.getElementById('theList');
|
chrome.tabs.sendMessage(
|
||||||
list.innerHTML = "";
|
tabs[0].id,
|
||||||
for(var key in items){
|
{
|
||||||
if(key !== DISABLE_KEY){
|
input_word: input_word,
|
||||||
var k;
|
replace_value: replacement
|
||||||
if(key=="person")
|
})
|
||||||
k = "Y/N";
|
})
|
||||||
else
|
}
|
||||||
k = key;
|
}
|
||||||
var v = items[key];
|
|
||||||
var rep = k + " -> " + v;
|
const loadSaved = () => {
|
||||||
var text = document.createTextNode(rep);
|
chrome.storage.local.get(null, items => {
|
||||||
var node = document.createElement("LI");
|
const list = document.getElementById('saved-items-list')
|
||||||
node.appendChild(text);
|
list.innerHTML = ''
|
||||||
node.id = key;
|
let hasItems = false
|
||||||
node.className = 'one-saved-item';
|
for (var key in items) {
|
||||||
node.addEventListener('click', function(){
|
if (key !== DEACTIVATE_KEY) {
|
||||||
chrome.storage.local.remove(this.id);
|
const label = key === 'person' ? 'Y/N' : key
|
||||||
this.className+=' strikethrough';
|
const representative = `${label} -> ${items[key]}`
|
||||||
});
|
const list_item = createListItem(key, representative, 'one-saved-item')
|
||||||
list.appendChild(node);
|
list.appendChild(list_item)
|
||||||
|
hasItems = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
if (!hasItems) {
|
||||||
});
|
list.innerHTML = '<small>No stored replacements yet!</small>'
|
||||||
document.getElementById('clear-name').addEventListener('click', function(){ chrome.storage.local.remove("person", chrome.tabs.reload()) } );
|
|
||||||
var others = document.getElementsByClassName('changeForm');
|
|
||||||
for(var i=0; i<others.length; i++)
|
|
||||||
others[i].addEventListener('submit', otherHandler);
|
|
||||||
}); //instead of onclick="clickHandler()" in popup.html
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function otherHandler(){
|
|
||||||
var myInput = this.replaceWord.value;
|
|
||||||
if(myInput){
|
|
||||||
var valChange = myInput;
|
|
||||||
var isYN;
|
|
||||||
var replace;
|
|
||||||
if(this.replaceWith){
|
|
||||||
isYN = false;
|
|
||||||
replace = this.replaceWith.value;
|
|
||||||
if(this.isPerm.checked){
|
|
||||||
var obj = {};
|
|
||||||
obj[valChange] = replace;
|
|
||||||
chrome.storage.local.set(obj);
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
else{
|
}
|
||||||
isYN = true;
|
|
||||||
replace = 'NOPE'; // should/will never get accessed
|
|
||||||
}
|
|
||||||
|
|
||||||
chrome.tabs.query({active:true,currentWindow:true}, function(tab){
|
const createListItem = (id, text, className) => {
|
||||||
chrome.tabs.sendMessage(tab[0].id, {stuff:valChange, isYN: isYN, replaceVal:replace});
|
const text_node = document.createTextNode(text)
|
||||||
});
|
const list_node = document.createElement('LI')
|
||||||
}
|
list_node.appendChild(text_node)
|
||||||
|
list_node.className = className
|
||||||
|
list_node.id = id
|
||||||
|
list_node.addEventListener('click', () => {
|
||||||
|
chrome.storage.local.remove(id)
|
||||||
|
list_node.className += ' strikethrough'
|
||||||
|
})
|
||||||
|
return list_node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const setDeactivateKey = () => {
|
||||||
|
chrome.storage.local.get(DEACTIVATE_KEY, obj => {
|
||||||
|
const is_deactivated = obj[DEACTIVATE_KEY]
|
||||||
|
toggleDeactivateLabel(is_deactivated)
|
||||||
|
|
||||||
function clickHandler(){
|
if (is_deactivated) {
|
||||||
var person = document.getElementById("inputTxt").value;
|
const other_elements = document.getElementById('all-but-deactivate-wrapper')
|
||||||
if(person)
|
other_elements.style.opacity = '0.5'
|
||||||
chrome.storage.local.set({"person": person}, chrome.tabs.reload());
|
const input_elements = document.getElementsByTagName('INPUT')
|
||||||
|
Array.from(input_elements).forEach(input => {
|
||||||
|
if (input.id !== 'deactivate') {
|
||||||
|
input.disabled = 'disabled'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toggleDeactivateLabel = (reactivateBool) => {
|
||||||
|
const prefix = reactivateBool ? 'Re-activate' : 'Deactivate'
|
||||||
|
const deactivate_button = document.getElementById('deactivate')
|
||||||
|
deactivate_button.value = `${prefix} Extension`
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleDeactivate = () => {
|
||||||
|
chrome.storage.local.get(DEACTIVATE_KEY, obj => {
|
||||||
|
const was_deactivated = obj[DEACTIVATE_KEY]
|
||||||
|
toggleDeactivateLabel(!was_deactivated)
|
||||||
|
|
||||||
|
if (was_deactivated) {
|
||||||
|
chrome.storage.local.remove(DEACTIVATE_KEY)
|
||||||
|
} else {
|
||||||
|
const new_object = {}
|
||||||
|
new_object[DEACTIVATE_KEY] = true
|
||||||
|
chrome.storage.local.set(new_object)
|
||||||
|
}
|
||||||
|
|
||||||
|
chrome.tabs.reload()
|
||||||
|
window.close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue