From 2aa400e58dbeb9f7a18ab71805e62cdc31a42eca Mon Sep 17 00:00:00 2001 From: Girish Budhwani Date: Sat, 21 Dec 2019 15:42:31 +0530 Subject: [PATCH] Added functionality to highlight user list --- words_discoverer_chrome/adjust.html | 3 +++ words_discoverer_chrome/adjust.js | 1 + words_discoverer_chrome/background.js | 10 ++++++++++ words_discoverer_chrome/content_script.js | 16 +++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/words_discoverer_chrome/adjust.html b/words_discoverer_chrome/adjust.html index cd38eaa..859bb35 100644 --- a/words_discoverer_chrome/adjust.html +++ b/words_discoverer_chrome/adjust.html @@ -304,6 +304,9 @@ Example of highlighted English expression.

+ + Enable user words highlighting
+ diff --git a/words_discoverer_chrome/adjust.js b/words_discoverer_chrome/adjust.js index bb4d961..94cc5a8 100644 --- a/words_discoverer_chrome/adjust.js +++ b/words_discoverer_chrome/adjust.js @@ -382,6 +382,7 @@ function process_display() { handle_rb_loop(ib_rb_ids, wd_hl_settings.idiomParams, "backgroundColor"); add_cb_event_listener("wordsEnabled", wd_hl_settings.wordParams, "enabled"); + add_cb_event_listener("userWordsEnabled", wd_hl_settings.userWordParams, "enabled"); add_cb_event_listener("idiomsEnabled", wd_hl_settings.idiomParams, "enabled"); add_cb_event_listener("wordsBold", wd_hl_settings.wordParams, "bold"); add_cb_event_listener("idiomsBold", wd_hl_settings.idiomParams, "bold"); diff --git a/words_discoverer_chrome/background.js b/words_discoverer_chrome/background.js index c05af00..b256cd4 100644 --- a/words_discoverer_chrome/background.js +++ b/words_discoverer_chrome/background.js @@ -466,9 +466,19 @@ function initialize_extension() { useColor: true, color: "blue" }; + user_word_hl_params = { + enabled: true, + quoted: false, + bold: true, + useBackground: false, + backgroundColor: "rgb(255, 248, 220)", + useColor: true, + color: "green" + } wd_hl_settings = { wordParams: word_hl_params, idiomParams: idiom_hl_params, + userWordParams: user_word_hl_params }; chrome.storage.local.set({"wd_hl_settings": wd_hl_settings}); } diff --git a/words_discoverer_chrome/content_script.js b/words_discoverer_chrome/content_script.js index 05a1218..1a3b2c6 100644 --- a/words_discoverer_chrome/content_script.js +++ b/words_discoverer_chrome/content_script.js @@ -176,6 +176,17 @@ function text_to_hl_nodes(text, dst) { } num_nonempty += 1; var match = undefined; + + //finding user vocabulary + if (!match && wd_hl_settings.userWordParams.enabled) { + if (user_vocabulary.hasOwnProperty(tokens[wnum])) { + match = {normalized: tokens[wnum], kind: "userWord", begin: ibegin, end: ibegin + tokens[wnum].length}; + ibegin += tokens[wnum].length + 1; + wnum += 1; + num_good += 1; + } + } + if (!match && wd_hl_settings.idiomParams.enabled) { var lwnum = wnum; //look ahead word number var libegin = ibegin; //look ahead word begin @@ -236,7 +247,10 @@ function text_to_hl_nodes(text, dst) { for (var i = 0; i < matches.length; i++) { text_style = undefined; match = matches[i]; - if (match.kind === "lemma") { + if (match.kind == "userWord") { + hlParams = wd_hl_settings.userWordParams; + text_style = make_hl_style(hlParams); + } else if (match.kind === "lemma") { hlParams = wd_hl_settings.wordParams; text_style = make_hl_style(hlParams); } else if (match.kind === "idiom") {