add support for audio playback by pressing P
This commit is contained in:
1 parent
2cd5f4346d
commit
f32fd503c8
4 files changed
+128384
-41
No files matched your search
+67
-32
@@ -105,10 +105,10 @@ let lookup_kana = new Map();
|
|||||||
|
|
||||||
let dictsloaded = 0;
|
let dictsloaded = 0;
|
||||||
|
|
||||||
|
let lookup_audio = new Set();
|
||||||
|
|
||||||
function builddict()
|
function builddict()
|
||||||
{
|
{
|
||||||
//console.log("load");
|
|
||||||
//console.log(this);
|
|
||||||
if (this.readyState === 4)
|
if (this.readyState === 4)
|
||||||
{
|
{
|
||||||
if (this.status === 200)
|
if (this.status === 200)
|
||||||
@@ -121,32 +121,26 @@ function builddict()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
function build_audio_table()
|
||||||
function handle_error()
|
|
||||||
{
|
{
|
||||||
console.log("error");
|
if (this.readyState === 4)
|
||||||
console.log(this.responseURL);
|
{
|
||||||
|
if (this.status === 200)
|
||||||
|
{
|
||||||
|
let i = 0;
|
||||||
|
let j = 0;
|
||||||
|
while ((j = this.responseText.indexOf("\n", i)) !== -1)
|
||||||
|
{
|
||||||
|
lookup_audio.add(this.responseText.substring(i, j));
|
||||||
|
i = j + 1;
|
||||||
|
}
|
||||||
|
lookup_audio.add(this.responseText.substring(i));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
console.error(xhr.statusText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_progress()
|
|
||||||
{
|
|
||||||
console.log("progress");
|
|
||||||
console.log(this.responseURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handle_abort()
|
|
||||||
{
|
|
||||||
console.log("abort");
|
|
||||||
console.log(this.responseURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handle_timeout()
|
|
||||||
{
|
|
||||||
console.log("timeout");
|
|
||||||
console.log(this.responseURL);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Having a >4MB flat text file with stupid adhoc formatting is okay
|
// Having a >4MB flat text file with stupid adhoc formatting is okay
|
||||||
// but having a >4MB json file with nothing weird in it isn't
|
// but having a >4MB json file with nothing weird in it isn't
|
||||||
// Thanks, linter team!
|
// Thanks, linter team!
|
||||||
@@ -154,12 +148,15 @@ function load_part_of_dictionary(filename)
|
|||||||
{
|
{
|
||||||
let req = new XMLHttpRequest();
|
let req = new XMLHttpRequest();
|
||||||
req.addEventListener("load", builddict);
|
req.addEventListener("load", builddict);
|
||||||
/*
|
req.open("GET", browser.extension.getURL(filename));
|
||||||
req.addEventListener("error", handle_error);
|
req.send();
|
||||||
req.addEventListener("progress", handle_progress);
|
return req;
|
||||||
req.addEventListener("abort", handle_abort);
|
}
|
||||||
req.addEventListener("timeout", handle_timeout);
|
|
||||||
*/
|
function load_jdic_audio_table(filename)
|
||||||
|
{
|
||||||
|
let req = new XMLHttpRequest();
|
||||||
|
req.addEventListener("load", build_audio_table);
|
||||||
req.open("GET", browser.extension.getURL(filename));
|
req.open("GET", browser.extension.getURL(filename));
|
||||||
req.send();
|
req.send();
|
||||||
return req;
|
return req;
|
||||||
@@ -177,6 +174,8 @@ load_part_of_dictionary("dict/JMdict9.json");
|
|||||||
load_part_of_dictionary("dict/JMdict10.json");
|
load_part_of_dictionary("dict/JMdict10.json");
|
||||||
load_part_of_dictionary("dict/JMdict11.json");
|
load_part_of_dictionary("dict/JMdict11.json");
|
||||||
|
|
||||||
|
load_jdic_audio_table("dict/jdic audio.txt");
|
||||||
|
|
||||||
function buildlookups()
|
function buildlookups()
|
||||||
{
|
{
|
||||||
// Build map of spellings to dictionary entry.
|
// Build map of spellings to dictionary entry.
|
||||||
@@ -1394,6 +1393,42 @@ function restrict_by_text(entry, text)
|
|||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_extra_info(results)
|
||||||
|
{
|
||||||
|
for(let lookup of results)
|
||||||
|
{
|
||||||
|
for(let entry of lookup.result)
|
||||||
|
{
|
||||||
|
entry.has_audio = [];
|
||||||
|
if(!entry.k_ele || entry.k_ele.length == 0)
|
||||||
|
{
|
||||||
|
for(let r of entry.r_ele)
|
||||||
|
{
|
||||||
|
if(lookup_audio.has(r.reb))
|
||||||
|
{
|
||||||
|
entry.has_audio.push(r.reb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(entry.k_ele)
|
||||||
|
{
|
||||||
|
for(let k of entry.k_ele)
|
||||||
|
{
|
||||||
|
for(let r of entry.r_ele)
|
||||||
|
{
|
||||||
|
let test_string = r.reb + ";" + k.keb;
|
||||||
|
if(lookup_audio.has(test_string))
|
||||||
|
{
|
||||||
|
entry.has_audio.push(test_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return add_epwing_info(results);
|
||||||
|
}
|
||||||
|
|
||||||
// Skip JMdict entries reappearing in alternative lookups (so only the first one is shown)
|
// Skip JMdict entries reappearing in alternative lookups (so only the first one is shown)
|
||||||
function skip_rereferenced_entries(results)
|
function skip_rereferenced_entries(results)
|
||||||
{
|
{
|
||||||
@@ -1415,7 +1450,7 @@ function skip_rereferenced_entries(results)
|
|||||||
if(newlookup.length > 0)
|
if(newlookup.length > 0)
|
||||||
newresults.push({text:lookup.text, result:newlookup});
|
newresults.push({text:lookup.text, result:newlookup});
|
||||||
}
|
}
|
||||||
return add_epwing_info(newresults); // add epwing entries now
|
return add_extra_info(newresults); // add extra information like epwing results and audio data now
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_lookup = "";
|
let last_lookup = "";
|
||||||
|
|||||||
+128273
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -40,12 +40,12 @@
|
|||||||
"dict/JMdict9.json",
|
"dict/JMdict9.json",
|
||||||
"dict/JMdict10.json",
|
"dict/JMdict10.json",
|
||||||
"dict/JMdict11.json",
|
"dict/JMdict11.json",
|
||||||
|
"dict/jdic audio.txt",
|
||||||
"reader.js",
|
"reader.js",
|
||||||
"reader.html",
|
"reader.html",
|
||||||
"mining.js",
|
"mining.js",
|
||||||
"mining.html",
|
"mining.html",
|
||||||
"jmdictabbreviations.html",
|
"jmdictabbreviations.html"
|
||||||
"etc/popupbase.css"
|
|
||||||
],
|
],
|
||||||
|
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|||||||
+42
-7
@@ -371,7 +371,7 @@ function clip(str)
|
|||||||
|
|
||||||
// Here we actually build the content of the lookup popup, based on the text we looked up and the list of lookups from the background script
|
// Here we actually build the content of the lookup popup, based on the text we looked up and the list of lookups from the background script
|
||||||
// note that we can get multiple lookups and this function only handles a single lookup
|
// note that we can get multiple lookups and this function only handles a single lookup
|
||||||
function build_div_inner (text, result, moreText, index, first_of_many = false)
|
function build_div_inner(text, result, moreText, index, first_of_many = false)
|
||||||
{
|
{
|
||||||
//console.log("building div for " + text);
|
//console.log("building div for " + text);
|
||||||
//console.log(result);
|
//console.log(result);
|
||||||
@@ -512,6 +512,18 @@ function build_div_inner (text, result, moreText, index, first_of_many = false)
|
|||||||
else
|
else
|
||||||
continue; // shouldn't happen, but again, just in case of broken data
|
continue; // shouldn't happen, but again, just in case of broken data
|
||||||
|
|
||||||
|
if(term.has_audio.length > 0)
|
||||||
|
{
|
||||||
|
for(let audio of term.has_audio)
|
||||||
|
{
|
||||||
|
let audio_data_holder = document.createElement("div");
|
||||||
|
audio_data_holder.className = "nazeka_audioref";
|
||||||
|
audio_data_holder.style.display = "none";
|
||||||
|
audio_data_holder.innerText += audio+"\n";
|
||||||
|
container.appendChild(audio_data_holder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let temptag = document.createElement("span");
|
let temptag = document.createElement("span");
|
||||||
temptag.className = "nazeka_word";
|
temptag.className = "nazeka_word";
|
||||||
let original_kana = "";
|
let original_kana = "";
|
||||||
@@ -1396,7 +1408,7 @@ function update(event)
|
|||||||
offset = undefined;
|
offset = undefined;
|
||||||
hitrect = undefined;
|
hitrect = undefined;
|
||||||
}
|
}
|
||||||
if(x > hitrect.right+5 || x < hitrect.left-5 || y > hitrect.bottom+5 || y < hitrect.top-5)
|
if(hitrect && (x > hitrect.right+5 || x < hitrect.left-5 || y > hitrect.bottom+5 || y < hitrect.top-5))
|
||||||
{
|
{
|
||||||
textNode = undefined;
|
textNode = undefined;
|
||||||
offset = undefined;
|
offset = undefined;
|
||||||
@@ -1541,8 +1553,32 @@ async function mine_to_storage(object)
|
|||||||
browser.storage.local.set({cards:cards});
|
browser.storage.local.set({cards:cards});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function try_to_play_audio(object)
|
||||||
|
{
|
||||||
|
if(!exists_div())
|
||||||
|
return;
|
||||||
|
let mydiv = get_div().querySelector(".nazeka_audioref");
|
||||||
|
if(mydiv)
|
||||||
|
{
|
||||||
|
let text = mydiv.innerText;
|
||||||
|
let url;
|
||||||
|
if(text.includes(";"))
|
||||||
|
{
|
||||||
|
let fields = text.split(";");
|
||||||
|
url = "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kana=" + fields[0] + "&kanji=" + fields[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
url = "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kana=" + text + "&kanji=" + text;
|
||||||
|
let audio = new Audio(url);
|
||||||
|
audio.volume = 0.2;
|
||||||
|
audio.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function mine(highlight)
|
function mine(highlight)
|
||||||
{
|
{
|
||||||
|
// TODO mine audio information
|
||||||
|
|
||||||
let front = highlight.textContent;
|
let front = highlight.textContent;
|
||||||
let word = highlight.parentElement.parentElement;
|
let word = highlight.parentElement.parentElement;
|
||||||
let readings = "";
|
let readings = "";
|
||||||
@@ -1555,11 +1591,6 @@ function mine(highlight)
|
|||||||
let index = word.parentElement.querySelector(".nazeka_lookup_index");
|
let index = word.parentElement.querySelector(".nazeka_lookup_index");
|
||||||
let seq = word.getAttribute("nazeka_seq");
|
let seq = word.getAttribute("nazeka_seq");
|
||||||
|
|
||||||
//console.log(front);
|
|
||||||
//console.log(readings);
|
|
||||||
//console.log(definitions);
|
|
||||||
//console.log(seq);
|
|
||||||
|
|
||||||
mine_to_storage({front: front, readings: readings, definitions: definitions, lookup: lookup.textContent, sentence: sentence.textContent, index: index.textContent, seq: seq});
|
mine_to_storage({front: front, readings: readings, definitions: definitions, lookup: lookup.textContent, sentence: sentence.textContent, index: index.textContent, seq: seq});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1648,6 +1679,10 @@ function keytest(event)
|
|||||||
settings.sticky = !settings.sticky;
|
settings.sticky = !settings.sticky;
|
||||||
browser.storage.local.set({"sticky":settings.sticky});
|
browser.storage.local.set({"sticky":settings.sticky});
|
||||||
}
|
}
|
||||||
|
if(event.key == "p")
|
||||||
|
{
|
||||||
|
try_to_play_audio();
|
||||||
|
}
|
||||||
if(event.key == "ArrowLeft")
|
if(event.key == "ArrowLeft")
|
||||||
{
|
{
|
||||||
lookup_left();
|
lookup_left();
|
||||||
|
|||||||
Reference in new issue
Block a user