From f1d65e17a42521be4bc40a7b039888de2a9e5781 Mon Sep 17 00:00:00 2001 From: lidengke <2009lidengke@163.com> Date: Tue, 28 Mar 2023 15:02:30 +0800 Subject: [PATCH 1/4] fix: disable_by_keypress can't become false. --- words_discoverer_chrome/content_script.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/words_discoverer_chrome/content_script.js b/words_discoverer_chrome/content_script.js index 40088d3..6f6abcf 100644 --- a/words_discoverer_chrome/content_script.js +++ b/words_discoverer_chrome/content_script.js @@ -524,6 +524,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); From e9d8ba17098e4935f2fc41b648ad436572512bbc Mon Sep 17 00:00:00 2001 From: nameldk <2009lidengke@gmail.com> Date: Thu, 9 May 2024 09:44:21 +0800 Subject: [PATCH 2/4] fix: tabs permission --- words_discoverer_chrome/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/words_discoverer_chrome/manifest.json b/words_discoverer_chrome/manifest.json index ef063ff..aa4e48f 100644 --- a/words_discoverer_chrome/manifest.json +++ b/words_discoverer_chrome/manifest.json @@ -14,6 +14,7 @@ }, "author": "Dmitry Ignatovich", "permissions": [ + "tabs", "storage", "unlimitedStorage", "contextMenus", From a542afa903a6efab3f941b85f8c70f1bd6a430a8 Mon Sep 17 00:00:00 2001 From: nameldk <2009lidengke@gmail.com> Date: Thu, 9 May 2024 14:59:07 +0800 Subject: [PATCH 3/4] fix: dict word may end with \r\n. web page word will search from dict and use the result to match user_vocabulary. --- words_discoverer_chrome/background.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/words_discoverer_chrome/background.js b/words_discoverer_chrome/background.js index 9114a0f..234918e 100644 --- a/words_discoverer_chrome/background.js +++ b/words_discoverer_chrome/background.js @@ -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}); @@ -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}); From 3b4b6d7b060c0bd23eb5233944de9921483daa29 Mon Sep 17 00:00:00 2001 From: nameldk <2009lidengke@gmail.com> Date: Thu, 9 May 2024 15:43:49 +0800 Subject: [PATCH 4/4] fix: use span instead of customtag with a -. --- words_discoverer_chrome/content_script.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/words_discoverer_chrome/content_script.js b/words_discoverer_chrome/content_script.js index 6f6abcf..b98fb26 100644 --- a/words_discoverer_chrome/content_script.js +++ b/words_discoverer_chrome/content_script.js @@ -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;