Skip to content

Commit

Permalink
created a blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeisho committed Nov 19, 2021
1 parent dd13678 commit 7ad621c
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 32 deletions.
Binary file modified Archive.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!",

Expand All @@ -27,7 +27,7 @@
"page": "options.html"
},

"permissions": ["storage", "management"],
"permissions": ["tabs","storage", "management"],

"browser_specific_settings": {
"gecko": {
Expand Down
16 changes: 13 additions & 3 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@
<body>

<form>

<input type="checkBox" id="isOn"> </input>
<p id="chromeText">Options will be loaded for all new pages on Chrome. Alternatively reload the page.</p>
<select id="voiceSelect"></select>
<div >
<input type="checkBox" id="isOn">Active</input>
</div>
<div class="horizontal">
<button type="button" id="blacklist">blacklist</button>
<select id="voiceSelect" class="voiceSelect"></select>
</div>

</form>

<script src="options.js"></script>

</body>

<style>
body {width: 220px}
select {width: 50%}
.horizontal {display: flex, flex-direction: row}
</style>
</html>
120 changes: 97 additions & 23 deletions options.js
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);
22 changes: 18 additions & 4 deletions pronounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);




0 comments on commit 7ad621c

Please sign in to comment.