add another json dictionary option
This commit is contained in:
1 parent
74d808bc84
commit
d5d6bf6513
3 files changed
+63
-62
No files matched your search
+26
-39
@@ -704,7 +704,7 @@ function epwing_lookup_kana_inexact(kana)
|
||||
return possibilities;
|
||||
}
|
||||
|
||||
function add_epwing_info(lookups, strict_epwing)
|
||||
function add_epwing_info(lookups, other_settings)
|
||||
{
|
||||
for(let lookup of lookups)
|
||||
{
|
||||
@@ -720,7 +720,7 @@ function add_epwing_info(lookups, strict_epwing)
|
||||
|
||||
if(entry.k_ele)
|
||||
{
|
||||
let spellings = [];
|
||||
let spellings = [lookup.text, foundtext];
|
||||
for(let spelling of entry.k_ele)
|
||||
spellings.push(spelling.keb);
|
||||
let readings = [];
|
||||
@@ -728,31 +728,18 @@ function add_epwing_info(lookups, strict_epwing)
|
||||
readings.push(reading.reb);
|
||||
|
||||
// try exact matches
|
||||
// lookup
|
||||
let possibilities = epwing_lookup_kanji([lookup.text], readings, false);
|
||||
// main spelling
|
||||
if(possibilities.length == 0)
|
||||
possibilities = epwing_lookup_kanji([foundtext], readings, false);
|
||||
// all possible spellings
|
||||
if(possibilities.length == 0)
|
||||
possibilities = epwing_lookup_kanji(spellings, readings, false);
|
||||
let possibilities = epwing_lookup_kanji(spellings, readings, false);
|
||||
// try inexact matches
|
||||
if(!strict_epwing)
|
||||
{
|
||||
if(possibilities.length == 0)
|
||||
possibilities = epwing_lookup_kanji([lookup.text], readings, true);
|
||||
if(possibilities.length == 0)
|
||||
possibilities = epwing_lookup_kanji([foundtext], readings, true);
|
||||
if(possibilities.length == 0)
|
||||
if(possibilities.length == 0 && !other_settings.strict_epwing)
|
||||
possibilities = epwing_lookup_kanji(spellings, readings, true);
|
||||
}
|
||||
|
||||
if(possibilities.length > 0)
|
||||
epwing_data = copy(epwing[possibilities[0]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
let possibilities = epwing_lookup_kana_exact(foundtext);
|
||||
if(!strict_epwing)
|
||||
if(!other_settings.strict_epwing)
|
||||
{
|
||||
for(let reading of entry.r_ele)
|
||||
{
|
||||
@@ -1120,7 +1107,7 @@ function restrict_by_text(entry, text)
|
||||
return term;
|
||||
}
|
||||
|
||||
function add_extra_info(results, strict_epwing)
|
||||
function add_extra_info(results, other_settings)
|
||||
{
|
||||
for(let lookup of results)
|
||||
{
|
||||
@@ -1153,11 +1140,11 @@ function add_extra_info(results, strict_epwing)
|
||||
}
|
||||
}
|
||||
}
|
||||
return add_epwing_info(results, strict_epwing);
|
||||
return add_epwing_info(results, other_settings);
|
||||
}
|
||||
|
||||
// Skip JMdict entries reappearing in alternative lookups (so only the first one is shown)
|
||||
function skip_rereferenced_entries(results, strict_epwing)
|
||||
function skip_rereferenced_entries(results, other_settings)
|
||||
{
|
||||
let newresults = [];
|
||||
let seenseq = new Set();
|
||||
@@ -1175,12 +1162,12 @@ function skip_rereferenced_entries(results, strict_epwing)
|
||||
if(newlookup.length > 0)
|
||||
newresults.push({text:lookup.text, result:newlookup});
|
||||
}
|
||||
return add_extra_info(newresults, strict_epwing); // add extra information like epwing results and audio data now
|
||||
return add_extra_info(newresults, other_settings); // add extra information like epwing results and audio data now
|
||||
}
|
||||
|
||||
let last_lookup = "";
|
||||
let last_time_lookup = Date.now();
|
||||
function lookup_indirect(text, time, divexisted, alternatives_mode, strict_alternatives, strict_epwing)
|
||||
function lookup_indirect(text, time, divexisted, other_settings)
|
||||
{
|
||||
if(text == "")
|
||||
return;
|
||||
@@ -1195,7 +1182,7 @@ function lookup_indirect(text, time, divexisted, alternatives_mode, strict_alter
|
||||
// deconjugate() returns possible deconjugations, one of which has zero deconjugations, i.e. the plain text
|
||||
// build_lookup_comb looks for dictionary definitions matching any deconjugation, returning a list of them
|
||||
// FIXME: later lookups using definitions already caught
|
||||
if(alternatives_mode == 0 || alternatives_mode == 1 || alternatives_mode == 2)
|
||||
if(other_settings.alternatives_mode == 0 || other_settings.alternatives_mode == 1 || other_settings.alternatives_mode == 2)
|
||||
{
|
||||
let forms = deconjugate(text);
|
||||
let result = build_lookup_comb(forms);
|
||||
@@ -1208,9 +1195,9 @@ function lookup_indirect(text, time, divexisted, alternatives_mode, strict_alter
|
||||
if(result !== undefined && result.length > 0)
|
||||
{
|
||||
result = sort_results(text, result);
|
||||
if(alternatives_mode == 0 || text.length <= 1)
|
||||
return skip_rereferenced_entries([{text:text, result:result}], strict_epwing);
|
||||
else if(alternatives_mode == 1) // second longest too
|
||||
if(other_settings.alternatives_mode == 0 || text.length <= 1)
|
||||
return skip_rereferenced_entries([{text:text, result:result}], other_settings);
|
||||
else if(other_settings.alternatives_mode == 1) // second longest too
|
||||
{
|
||||
let len = text.length-1;
|
||||
let short_text = text.substring(0, len);
|
||||
@@ -1224,17 +1211,17 @@ function lookup_indirect(text, time, divexisted, alternatives_mode, strict_alter
|
||||
short_forms = deconjugate(short_text);
|
||||
short_result = build_lookup_comb(short_forms);
|
||||
}
|
||||
if(strict_alternatives && is_kana(short_text))
|
||||
if(other_settings.strict_alternatives && is_kana(short_text))
|
||||
short_result = filter_kana_ish_results(short_result);
|
||||
if(short_result !== undefined && short_result.length > 0)
|
||||
{
|
||||
short_result = sort_results(short_text, short_result);
|
||||
return skip_rereferenced_entries([{text:text, result:result}, {text:short_text, result:short_result}], strict_epwing);
|
||||
return skip_rereferenced_entries([{text:text, result:result}, {text:short_text, result:short_result}], other_settings);
|
||||
}
|
||||
else
|
||||
return skip_rereferenced_entries([{text:text, result:result}], strict_epwing);
|
||||
return skip_rereferenced_entries([{text:text, result:result}], other_settings);
|
||||
}
|
||||
else if(alternatives_mode == 2) // shortest too
|
||||
else if(other_settings.alternatives_mode == 2) // shortest too
|
||||
{
|
||||
let len = 1;
|
||||
let short_text = text.substring(0, len);
|
||||
@@ -1248,19 +1235,19 @@ function lookup_indirect(text, time, divexisted, alternatives_mode, strict_alter
|
||||
short_forms = deconjugate(short_text);
|
||||
short_result = build_lookup_comb(short_forms);
|
||||
}
|
||||
if(strict_alternatives && is_kana(short_text))
|
||||
if(other_settings.strict_alternatives && is_kana(short_text))
|
||||
short_result = filter_kana_ish_results(short_result);
|
||||
if(short_result !== undefined && short_result.length > 0)
|
||||
{
|
||||
short_result = sort_results(short_text, short_result);
|
||||
return skip_rereferenced_entries([{text:text, result:result}, {text:short_text, result:short_result}], strict_epwing);
|
||||
return skip_rereferenced_entries([{text:text, result:result}, {text:short_text, result:short_result}], other_settings);
|
||||
}
|
||||
else
|
||||
return skip_rereferenced_entries([{text:text, result:result}], strict_epwing);
|
||||
return skip_rereferenced_entries([{text:text, result:result}], other_settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(alternatives_mode == 3)
|
||||
else if(other_settings.alternatives_mode == 3)
|
||||
{
|
||||
let results = [];
|
||||
let first = true;
|
||||
@@ -1269,7 +1256,7 @@ function lookup_indirect(text, time, divexisted, alternatives_mode, strict_alter
|
||||
let forms = deconjugate(text);
|
||||
let result = build_lookup_comb(forms);
|
||||
|
||||
if(!first && strict_alternatives && is_kana(text))
|
||||
if(!first && other_settings.strict_alternatives && is_kana(text))
|
||||
result = filter_kana_ish_results(result);
|
||||
|
||||
if(result !== undefined && result.length > 0)
|
||||
@@ -1282,7 +1269,7 @@ function lookup_indirect(text, time, divexisted, alternatives_mode, strict_alter
|
||||
first = false;
|
||||
}
|
||||
if(results.length > 0)
|
||||
return skip_rereferenced_entries(results, strict_epwing);
|
||||
return skip_rereferenced_entries(results, other_settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1422,7 +1409,7 @@ browser.runtime.onMessage.addListener((req, sender) =>
|
||||
{
|
||||
if (req.type == "search")
|
||||
{
|
||||
let asdf = lookup_indirect(req.text, req.time, req.divexisted, req.alternatives_mode, req.strict_alternatives, req.strict_epwing);
|
||||
let asdf = lookup_indirect(req.text, req.time, req.divexisted, req.settings);
|
||||
return Promise.resolve({"response" : asdf});
|
||||
}
|
||||
else if (req.type == "platform")
|
||||
|
||||
@@ -74,6 +74,12 @@ function defaults()
|
||||
default: 0,
|
||||
label: "Where to look for definitions (does not affect jmdict readings)"
|
||||
});
|
||||
settings.push({
|
||||
id: "normal_definitions_in_mining",
|
||||
kind: "checkbox",
|
||||
default: false,
|
||||
label: "Force \"From jmdict then json\" definitions mode when mining UI is open"
|
||||
});
|
||||
settings.push({
|
||||
id: "strict_epwing",
|
||||
kind: "checkbox",
|
||||
|
||||
+31
-23
@@ -22,9 +22,10 @@ fixedwidth: false,
|
||||
fixedwidthpositioning: false,
|
||||
superborder: false,
|
||||
showoriginal: true,
|
||||
definitions_mode: 0,
|
||||
normal_definitions_in_mining: false,
|
||||
alternatives_mode: 0, // 0: longest only; 1: longest and shortest; 2: longest and second longest; 3: all matches
|
||||
strict_alternatives: true, // if true, alternatives looked up in all kana can not return results with kanji glosses that don't have any usually/exclusively kana info
|
||||
definitions_mode: 0,
|
||||
strict_epwing: true,
|
||||
scale: 1,
|
||||
width: 600,
|
||||
@@ -156,6 +157,17 @@ function get_doc()
|
||||
return mydoc;
|
||||
}
|
||||
|
||||
function mining_ui_exists()
|
||||
{
|
||||
return get_doc().body.getElementsByClassName("nazeka_mining_ui").length > 0;
|
||||
}
|
||||
|
||||
function delete_mining_ui()
|
||||
{
|
||||
while(mining_ui_exists())
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
}
|
||||
|
||||
function getViewportSize(mydoc)
|
||||
{
|
||||
if (mydoc.compatMode == "CSS1Compat")
|
||||
@@ -271,7 +283,7 @@ function display_div(middle, x, y)
|
||||
|
||||
let corner = settings.corner;
|
||||
|
||||
if(settings.sticky && platform != "android" && get_doc().body.getElementsByClassName("nazeka_mining_ui").length == 0)
|
||||
if(settings.sticky && platform != "android" && !mining_ui_exists())
|
||||
set_sticky_styles(outer);
|
||||
else
|
||||
{
|
||||
@@ -568,7 +580,7 @@ function build_div_inner(text, result, moreText, index, first_of_many = false)
|
||||
original.appendChild(original_inner);
|
||||
original.appendChild(document.createTextNode(moreText_end));
|
||||
|
||||
if(first_of_many && (platform == "android" || (settings.sticky && get_doc().body.getElementsByClassName("nazeka_mining_ui").length == 0)))
|
||||
if(first_of_many && (platform == "android" || (settings.sticky && !mining_ui_exists())))
|
||||
{
|
||||
let buttons = document.createElement("div");
|
||||
let left_arrow = document.createElement("img");
|
||||
@@ -954,7 +966,7 @@ function build_div_inner(text, result, moreText, index, first_of_many = false)
|
||||
let jmdict_div = elementize_jmdict_defs(term.sense);
|
||||
let epwing_div = elementize_epwing_defs(term.epwing);
|
||||
|
||||
if (settings.definitions_mode == 0) // normal
|
||||
if (settings.definitions_mode == 0 || (settings.normal_definitions_in_mining && mining_ui_exists())) // normal
|
||||
{
|
||||
if(jmdict_div) definition.appendChild(jmdict_div);
|
||||
if(epwing_div) definition.appendChild(epwing_div);
|
||||
@@ -1071,6 +1083,7 @@ async function settings_init()
|
||||
getvar("alternatives_mode", 0);
|
||||
getvar("strict_alternatives", true);
|
||||
getvar("definitions_mode", 0);
|
||||
getvar("normal_definitions_in_mining", false);
|
||||
getvar("strict_epwing", true);
|
||||
|
||||
getvar("corner", 0);
|
||||
@@ -1100,7 +1113,7 @@ async function settings_init()
|
||||
delete_div();
|
||||
if(!settings.enabled)
|
||||
{
|
||||
while(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
while(mining_ui_exists())
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
}
|
||||
} catch(err) {} // options not stored yet
|
||||
@@ -1122,7 +1135,7 @@ browser.storage.onChanged.addListener((updates, storageArea) =>
|
||||
delete_div();
|
||||
if(!settings.enabled)
|
||||
{
|
||||
while(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
while(mining_ui_exists())
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
}
|
||||
});
|
||||
@@ -1140,9 +1153,11 @@ async function send_lookup(lookup)
|
||||
text:lookup[0],
|
||||
time:Date.now(),
|
||||
divexisted:exists_div(),
|
||||
settings:{
|
||||
alternatives_mode:settings.alternatives_mode,
|
||||
strict_alternatives:settings.strict_alternatives,
|
||||
strict_epwing:settings.strict_epwing
|
||||
}
|
||||
});
|
||||
if(response)
|
||||
response = response["response"];
|
||||
@@ -1172,7 +1187,7 @@ function lookup_enqueue(text, x, y, x2, y2, moreText, index)
|
||||
|
||||
function lookup_cancel()
|
||||
{
|
||||
if(!settings.sticky || get_doc().body.getElementsByClassName("nazeka_mining_ui").length != 0 || platform == "android")
|
||||
if(!settings.sticky || mining_ui_exists() || platform == "android")
|
||||
delete_div();
|
||||
}
|
||||
|
||||
@@ -1417,7 +1432,7 @@ function update(event)
|
||||
|
||||
if(!settings.enabled) return;
|
||||
|
||||
if(settings.popup_follows_mouse && exists_div() && platform != "android" && (!settings.sticky || get_doc().body.getElementsByClassName("nazeka_mining_ui").length != 0))
|
||||
if(settings.popup_follows_mouse && exists_div() && platform != "android" && (!settings.sticky || mining_ui_exists()))
|
||||
{
|
||||
let other = get_div();
|
||||
//let middle = other.firstChild.cloneNode(true);
|
||||
@@ -1484,7 +1499,7 @@ function update(event)
|
||||
range.detach();
|
||||
}
|
||||
// sticky mode and android need to break out on parent detection
|
||||
if(ele && !ele.contains(textNode) && platform != "android" && (!settings.sticky || get_doc().body.getElementsByClassName("nazeka_mining_ui").length != 0))
|
||||
if(ele && !ele.contains(textNode) && platform != "android" && (!settings.sticky || mining_ui_exists()))
|
||||
{
|
||||
textNode = undefined;
|
||||
offset = undefined;
|
||||
@@ -1505,7 +1520,7 @@ function update(event)
|
||||
hitpage(event.clientX, 0, event.clientY);
|
||||
}
|
||||
|
||||
if ((platform == "android" || (settings.sticky && get_doc().body.getElementsByClassName("nazeka_mining_ui").length == 0)) && exists_div())
|
||||
if ((platform == "android" || (settings.sticky && !mining_ui_exists())) && exists_div())
|
||||
{
|
||||
let ele = get_div();
|
||||
if(ele.contains(textNode))
|
||||
@@ -1844,19 +1859,15 @@ function keytest(event)
|
||||
return;
|
||||
if(event.key == settings.hotkey_mine)
|
||||
{
|
||||
if(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
if(mining_ui_exists())
|
||||
{
|
||||
while(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
{
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
}
|
||||
delete_mining_ui();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!exists_div())
|
||||
return;
|
||||
while(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
delete_mining_ui();
|
||||
|
||||
let mydiv = get_div().cloneNode(true);
|
||||
delete_div();
|
||||
@@ -1866,8 +1877,7 @@ function keytest(event)
|
||||
newheader.textContent = "Mining UI. Press the given entry's main spelling to mine it, or click this message to cancel.";
|
||||
newheader.addEventListener("click", ()=>
|
||||
{
|
||||
while(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
delete_mining_ui();
|
||||
});
|
||||
mydiv.firstChild.firstChild.prepend(newheader);
|
||||
mydiv.style.zIndex = 1000000000000000000000;
|
||||
@@ -1879,8 +1889,7 @@ function keytest(event)
|
||||
keb.addEventListener("click", (event)=>
|
||||
{
|
||||
mine(event.target);
|
||||
while(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
delete_mining_ui();
|
||||
});
|
||||
}
|
||||
for(let reb of mydiv.getElementsByClassName("nazeka_main_reb"))
|
||||
@@ -1888,8 +1897,7 @@ function keytest(event)
|
||||
reb.addEventListener("click", (event)=>
|
||||
{
|
||||
mine(event.target);
|
||||
while(get_doc().body.getElementsByClassName("nazeka_mining_ui").length)
|
||||
get_doc().body.getElementsByClassName("nazeka_mining_ui")[0].remove();
|
||||
delete_mining_ui();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user