fix deconj rule importing

This commit is contained in:
wareya committed 2018-11-04 07:18:18 -05:00
1 parent d809f4b87d
commit ebda48d6f5
2 files changed
+16 -4

No files matched your search

+9 -1
View File
@@ -552,13 +552,21 @@ function deconjugate(mytext)
let start_form = {text: mytext, original_text: mytext, tags: [], seentext: new Set(), process: [] }; let start_form = {text: mytext, original_text: mytext, tags: [], seentext: new Set(), process: [] };
novel.add(start_form); novel.add(start_form);
let myrules = rules;
try
{
if(settings.deconjugator_rules_json != "")
myrules = JSON.parse(settings.deconjugator_rules_json);
} catch(err) {}
while(novel.size > 0) while(novel.size > 0)
{ {
//print_object(novel); //print_object(novel);
let new_novel = new Set(); let new_novel = new Set();
for(let form of novel) for(let form of novel)
{ {
for(let rule of rules) for(let rule of myrules)
{ {
if(!(rule instanceof Object)) if(!(rule instanceof Object))
continue; continue;
+7 -3
View File
@@ -453,13 +453,17 @@ function buildpage()
decon_file.id = "decon_file"; decon_file.id = "decon_file";
decon_file.addEventListener("change", () => decon_file.addEventListener("change", () =>
{ {
let fname = document.querySelector("#epwing_file").files[0]; let fname = document.querySelector("#decon_file").files[0];
let reader = new FileReader(); let reader = new FileReader();
reader.onload = async(e) => reader.onload = async(e) =>
{ {
try try
{ {
browser.storage.local.set({"deconjugator_rules_json":JSON.stringify(JSON.parse(e.target.result))}); let text = e.target.result;
if(text == "" || text == "\n" || text == "\r\n")
browser.storage.local.set({"deconjugator_rules_json":""});
else
browser.storage.local.set({"deconjugator_rules_json":JSON.stringify(JSON.parse())});
document.querySelector("decon_label").textContent = "Imported. Might take a few seconds to apply."; document.querySelector("decon_label").textContent = "Imported. Might take a few seconds to apply.";
} }
catch(except) catch(except)
@@ -472,7 +476,7 @@ function buildpage()
let decon_label = document.createElement("label"); let decon_label = document.createElement("label");
decon_label.for = decon_file.id; decon_label.for = decon_file.id;
decon_label.id = "import_label"; decon_label.id = "import_label";
decon_label.textContent = "Import deconjugation ruleset. Overrides default deconjugation ruleset. Importing a blank file and restarting your browser will restore the default ruleset."; decon_label.textContent = "Import deconjugation ruleset. Overrides default deconjugation ruleset. Importing a blank file will restore the default ruleset.";
decon_label.style.display = "block"; decon_label.style.display = "block";
optionsection.appendChild(decon_file); optionsection.appendChild(decon_file);