Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

fix: disable_by_keypress can't become false. #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions words_discoverer_chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ function do_load_dictionary(file_text) {
var fields = lines[i].split('\t');
if (i + 1 === lines.length && fields.length == 1)
break;
var form = fields[0];
var lemma = fields[1];
var form = fields[0].trim();
var lemma = fields[1].trim();
if (lemma !== prev_lemma) {
rank += 1;
prev_lemma = lemma;
}
rare_words[fields[0]] = [fields[1], rank];
rare_words[form] = [lemma, rank];
}
local_storage = chrome.storage.local;
local_storage.set({"words_discoverer_eng_dict": rare_words});
Expand Down Expand Up @@ -52,7 +52,7 @@ function do_load_idioms(file_text) {
rare_words[key] = -1;
}
key = fields[0];
rare_words[key] = fields[1];
rare_words[key] = fields[1].trim();
}
local_storage = chrome.storage.local;
local_storage.set({"wd_idioms": rare_words});
Expand Down
15 changes: 13 additions & 2 deletions words_discoverer_chrome/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ function text_to_hl_nodes(text, dst) {
dst.push(document.createTextNode(text.slice(last_hl_end_pos, match.begin)));
}
last_hl_end_pos = match.end;
//span = document.createElement("span");
span = document.createElement("wdautohl-customtag");
span = document.createElement("span");
// wdautohl-customtag can not display in reddit, use _ instead of - can work.
// span = document.createElement("wdautohl-customtag");
span.textContent = text.slice(match.begin, last_hl_end_pos);
span.setAttribute("style", text_style);
span.id = 'wdautohl_id_' + cur_wd_node_id;
Expand Down Expand Up @@ -524,6 +525,16 @@ function initForPage() {
}
});

document.addEventListener("focusout", function (event) {
if (disable_by_keypress) {
let elementTagName = event.target.tagName;
if (elementTagName === 'TEXTAREA' || elementTagName === 'INPUT') {
disable_by_keypress = false;
chrome.runtime.sendMessage({wdm_verdict: "notInKeyboard"});
}
}
});

var textNodes = textNodesUnder(document.body);
doHighlightText(textNodes);

Expand Down
1 change: 1 addition & 0 deletions words_discoverer_chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"author": "Dmitry Ignatovich",
"permissions": [
"tabs",
"storage",
"unlimitedStorage",
"contextMenus",
Expand Down