-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
filipeisho
committed
Nov 19, 2021
1 parent
dd13678
commit 7ad621c
Showing
5 changed files
with
130 additions
and
32 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters