diff --git a/Archive.zip b/Archive.zip index 5264fa6..37f4ae0 100644 Binary files a/Archive.zip and b/Archive.zip differ diff --git a/manifest.json b/manifest.json index 8f50e8b..a150672 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Double-click pronounce", - "version": "2.4", + "version": "2.5.1", "description": "Never doubt how to pronounce a word. Better your spoken languages!", @@ -27,7 +27,7 @@ "page": "options.html" }, - "permissions": ["storage", "management"], + "permissions": ["tabs","storage", "management"], "browser_specific_settings": { "gecko": { diff --git a/options.html b/options.html index b8ef7f3..d5e4cc1 100644 --- a/options.html +++ b/options.html @@ -10,14 +10,24 @@
- -

Options will be loaded for all new pages on Chrome. Alternatively reload the page.

- +
+ Active +
+
+ + +
+
+ diff --git a/options.js b/options.js index 490111b..f9bbad6 100644 --- a/options.js +++ b/options.js @@ -1,63 +1,137 @@ - +async function getPage() {} function populateVoiceList() { - if(typeof speechSynthesis === 'undefined') { + if (typeof speechSynthesis === "undefined") { return; } var voices = speechSynthesis.getVoices(); - for(var i = 0; i < voices.length; i++) { - var option = document.createElement('option'); - option.textContent = voices[i].name + ' (' + voices[i].lang + ')'; - - if(voices[i].default) { - option.textContent += ' -- DEFAULT'; + for (var i = 0; i < voices.length; i++) { + var option = document.createElement("option"); + option.textContent = voices[i].name + " (" + voices[i].lang + ")"; + + if (voices[i].default) { + option.textContent += " -- DEFAULT"; } - option.setAttribute('data-lang', voices[i].lang); - option.setAttribute('data-name', voices[i].name); + option.setAttribute("data-lang", voices[i].lang); + option.setAttribute("data-name", voices[i].name); document.getElementById("voiceSelect").appendChild(option); } } populateVoiceList(); -if (typeof speechSynthesis !== 'undefined' && speechSynthesis.onvoiceschanged !== undefined) { +if ( + typeof speechSynthesis !== "undefined" && + speechSynthesis.onvoiceschanged !== undefined +) { speechSynthesis.onvoiceschanged = populateVoiceList; } function saveOptions(e) { e.preventDefault(); browser.storage.sync.set({ voiceSelect: document.querySelector("#voiceSelect").value, - isOn: document.querySelector("#isOn").checked + isOn: document.querySelector("#isOn").checked, + blacklist: JSON.stringify([""]), }); + browser.runtime.reload(); + window.close(); +} -browser.runtime.reload() -window.close(); +function url_domain(data) { + var a = document.createElement("a"); + a.href = data; + return a.hostname; } -function restoreOptions() { +function addToBlacklist(e) { + async function store(result) { + + blacklist = JSON.parse(result.blacklist); + current_url = await browser.tabs + .query({ currentWindow: true, active: true }) + .then((tabs) => { + return tabs[0].url; + }); + hostname = url_domain(current_url); + + if (!blacklist.includes(hostname)) { + blacklist.push(hostname); + + document.querySelector("#blacklist").innerHTML = 'de-blacklist'; + } + else { + index = blacklist.indexOf(hostname); + if (index > -1){ + blacklist.splice(index,1); + } + document.querySelector("#blacklist").innerHTML = 'blacklist'; + + } + + blacklist = JSON.stringify(blacklist); + e.preventDefault(); + browser.storage.sync.set({ + blacklist: blacklist, + }); + + console.log(blacklist); + browser.runtime.reload(); + window.close(); + } + + function onError(error) { + console.log('sldkfj'); + browser.storage.sync.set({ + blacklist: JSON.stringify([""]), + }); + } + let blacklist = browser.storage.sync.get("blacklist"); + blacklist.then(store, onError); +} + +function restoreOptions() { function setCurrentChoice(result) { - document.querySelector("#voiceSelect").value = result.voiceSelect || "en-US"; + document.querySelector("#voiceSelect").value = + result.voiceSelect || "en-US"; } - function setIsOn(result){ + function setIsOn(result) { document.querySelector("#isOn").checked = result.isOn || false; } - function onError(error) { + async function setBlacklist(result) { + blacklist = JSON.parse(result.blacklist); + current_url = await browser.tabs + .query({ currentWindow: true, active: true }) + .then((tabs) => { + return tabs[0].url; + }); + hostname = url_domain(current_url); + if (blacklist.includes(hostname)){ + document.querySelector("#blacklist").innerHTML = 'deblacklist'; + } + else{ + document.querySelector("#blacklist").innerHTML = 'blacklist'; + } } + function onError(error) {} let getting = browser.storage.sync.get("voiceSelect"); getting.then(setCurrentChoice, onError); let isOn = browser.storage.sync.get("isOn"); isOn.then(setIsOn, onError); + let blacklist = browser.storage.sync.get("blacklist"); + blacklist.then(setBlacklist, onError); } -var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); -if (!isChrome){ -document.querySelector("#chromeText").remove() +var isChrome = + /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); +if (!isChrome) { + document.querySelector("#chromeText").remove(); } -document.querySelector("#voiceSelect").addEventListener('change',saveOptions) -document.querySelector("#isOn").addEventListener('change',saveOptions) +document.querySelector("#voiceSelect").addEventListener("change", saveOptions); +document.querySelector("#isOn").addEventListener("change", saveOptions); +document.querySelector("#blacklist").addEventListener("click", addToBlacklist); document.addEventListener("DOMContentLoaded", restoreOptions); diff --git a/pronounce.js b/pronounce.js index 648cf41..de5c7ef 100644 --- a/pronounce.js +++ b/pronounce.js @@ -27,17 +27,31 @@ function onGot(item) { }; } +function url_domain(data) { + var a = document.createElement("a"); + a.href = data; + return a.hostname; +} -function onGotIsOn(isOn){ +async function onGotBlacklist(result){ + blacklist = JSON.parse(result.blacklist); + current_url = window.location.href + hostname = url_domain(current_url); + if (!blacklist.includes(hostname)){ + let isOn = browser.storage.sync.get("isOn"); + isOn.then(onGotIsOn, onError); + } +} +async function onGotIsOn(isOn){ if (isOn.isOn == true){ let getting = browser.storage.sync.get("voiceSelect"); getting.then(onGot, onError); } } - -let isOn = browser.storage.sync.get("isOn"); -isOn.then(onGotIsOn, onError); +let blacklist = browser.storage.sync.get("blacklist"); +blacklist.then(onGotBlacklist, onError); +