Skip to content

Commit

Permalink
added gecko (firefox) support
Browse files Browse the repository at this point in the history
  • Loading branch information
hugodecasta committed Apr 29, 2021
1 parent a80317d commit dd5756a
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 110 deletions.
7 changes: 6 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Wavenet reader",
"description": "Wavenet voice chrome page reader",
"version": "1.2",
"version": "1.3",
"manifest_version": 2,
"permissions": [
"activeTab",
Expand All @@ -19,5 +19,10 @@
},
"browser_action": {
"default_popup": "popup.html"
},
"browser_specific_settings": {
"gecko": {
"id": "wave-reader@hugodecast"
}
}
}
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wave_reader",
"version": "1.2.0",
"version": "1.3.0",
"description": "wavenet voice chrome page reader",
"main": "index.js",
"scripts": {
Expand Down
218 changes: 110 additions & 108 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,119 +1,121 @@
// ------------------------------------- METHODS

async function load_voices() {
try {
const client = new WAVENET_CLIENT(apikey_input.value)
const voices = await client.get_voices()
if ('error' in voices) throw 'cannot retrieve voices'

infos_p.innerHTML = ''
voice_titles_tr.innerHTML = ''
voice_selects_tr.innerHTML = ''
translate_langs_select.innerHTML = ''

const langs = Object.keys(Object.values(voices)[0])

langs.forEach(lang => {
let translate_lang_option = document.createElement('option')
translate_lang_option.value = lang
translate_lang_option.innerHTML = lang
translate_langs_select.appendChild(translate_lang_option)
})
translate_langs_select.value = translate_to
(async function () {
async function load_voices() {
try {
const client = new WAVENET_CLIENT(apikey_input.value)
const voices = await client.get_voices()
if ('error' in voices) throw 'cannot retrieve voices'

infos_p.innerHTML = ''
voice_titles_tr.innerHTML = ''
voice_selects_tr.innerHTML = ''
translate_langs_select.innerHTML = ''

const langs = Object.keys(Object.values(voices)[0])

const lang_select = {}
langs.forEach(lang => {
let title = document.createElement('th')
title.innerHTML = lang + ' voices'
voice_titles_tr.appendChild(title)
let td = document.createElement('td')
let select = document.createElement('select')
td.appendChild(select)
voice_selects_tr.appendChild(td)
lang_select[lang] = select
})

Object.keys(voices).forEach(voice_name => {
langs.forEach(lang => {
let voice_option = document.createElement('option')
voice_option.innerHTML = 'voice - ' + voice_name
voice_option.value = voice_name
lang_select[lang].appendChild(voice_option)
let translate_lang_option = document.createElement('option')
translate_lang_option.value = lang
translate_lang_option.innerHTML = lang
translate_langs_select.appendChild(translate_lang_option)
})
})
langs.forEach(lang => lang_select[lang].value = voices_name[lang])
langs.forEach(lang =>
lang_select[lang].onchange = () => {
voices_name[lang] = lang_select[lang].value
save_data()
translate_langs_select.value = translate_to

const lang_select = {}
langs.forEach(lang => {
let title = document.createElement('th')
title.innerHTML = lang + ' voices'
voice_titles_tr.appendChild(title)
let td = document.createElement('td')
let select = document.createElement('select')
td.appendChild(select)
voice_selects_tr.appendChild(td)
lang_select[lang] = select
})

Object.keys(voices).forEach(voice_name => {
langs.forEach(lang => {
let voice_option = document.createElement('option')
voice_option.innerHTML = 'voice - ' + voice_name
voice_option.value = voice_name
lang_select[lang].appendChild(voice_option)
})
})
return true
langs.forEach(lang => lang_select[lang].value = voices_name[lang])
langs.forEach(lang =>
lang_select[lang].onchange = () => {
voices_name[lang] = lang_select[lang].value
save_data()
})
return true
}
catch (e) {
console.error(e)
infos_p.innerHTML = 'wrong api key'
}
return false
}
catch (e) {
console.error(e)
infos_p.innerHTML = 'wrong api key'

function save_data() {
chrome.storage.sync.set({ apikey, voices_name, volume, translate_to });
}
return false
}

function save_data() {
chrome.storage.sync.set({ apikey, voices_name, volume, translate_to });
}

function get_data() {
return new Promise(ok => chrome.storage.sync.get(['apikey', 'voices_name', 'volume', 'translate_to'], ok))
}

// ------------------------------------- INIT

let { apikey, voices_name, volume, translate_to } = await get_data()
voices_name ||= {}
volume ||= 1
console.log(voices_name)

const apikey_input = document.getElementById('apikey')
const infos_p = document.getElementById('infos')
const volume_slider = document.getElementById('volume')
const force_translate_cb = document.getElementById('force_translate')
const translate_langs_select = document.getElementById('translate_langs')

apikey_input.value = apikey
volume_slider.value = volume * 100
force_translate_cb.checked = translate_to != null
translate_langs_select.value = translate_to
translate_langs_select.disabled = translate_to == null

const voice_titles_tr = document.getElementById('voice_titles')
const voice_selects_tr = document.getElementById('voice_selects')

await load_voices()

// ------------------------------------- EVENTS

force_translate_cb.onchange = async () => {
let checked = force_translate_cb.checked
if (!checked) translate_to = null
else {
const client = new WAVENET_CLIENT(apikey_input.value)
const voices = await client.get_voices()
translate_to = Object.keys(Object.values(voices)[0])[0]

function get_data() {
return new Promise(ok => chrome.storage.sync.get(['apikey', 'voices_name', 'volume', 'translate_to'], ok))
}

// ------------------------------------- INIT

let { apikey, voices_name, volume, translate_to } = await get_data()
voices_name ||= {}
volume ||= 1
console.log(voices_name)

const apikey_input = document.getElementById('apikey')
const infos_p = document.getElementById('infos')
const volume_slider = document.getElementById('volume')
const force_translate_cb = document.getElementById('force_translate')
const translate_langs_select = document.getElementById('translate_langs')

apikey_input.value = apikey
volume_slider.value = volume * 100
force_translate_cb.checked = translate_to != null
translate_langs_select.value = translate_to
translate_langs_select.disabled = translate_to == null
save_data()
}

translate_langs_select.onchange = () => {
translate_to = translate_langs_select.value
save_data()
}

apikey_input.onchange = async () => {
apikey = apikey_input.value
if (await load_voices()) save_data()
}

volume_slider.onchange = async () => {
volume = volume_slider.value / 100
save_data()
}

const voice_titles_tr = document.getElementById('voice_titles')
const voice_selects_tr = document.getElementById('voice_selects')

await load_voices()

// ------------------------------------- EVENTS

force_translate_cb.onchange = async () => {
let checked = force_translate_cb.checked
if (!checked) translate_to = null
else {
const client = new WAVENET_CLIENT(apikey_input.value)
const voices = await client.get_voices()
translate_to = Object.keys(Object.values(voices)[0])[0]
}
translate_langs_select.value = translate_to
translate_langs_select.disabled = translate_to == null
save_data()
}

translate_langs_select.onchange = () => {
translate_to = translate_langs_select.value
save_data()
}

apikey_input.onchange = async () => {
apikey = apikey_input.value
if (await load_voices()) save_data()
}

volume_slider.onchange = async () => {
volume = volume_slider.value / 100
save_data()
}
})()

0 comments on commit dd5756a

Please sign in to comment.