From 1dfe370983a7a8112b278f5bfce5fd5587104c49 Mon Sep 17 00:00:00 2001 From: Lan Hui <1348141770@qq.com> Date: Tue, 2 Aug 2022 11:39:35 +0800 Subject: [PATCH] Use better variable names --- app/static/js/highlight.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index 008f71e..b026e06 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -23,10 +23,10 @@ function getWord() { function highLight() { if (!isHighlight) return; let txt = document.getElementById("article").innerText; - let sel_word1 = document.getElementById("selected-words"); - let sel_word2 = document.getElementById("selected-words2"); - if (sel_word1 != null) { - const list = sel_word1.value.split(" "); + let picked_words = document.getElementById("selected-words"); + let dictionary_words = document.getElementById("selected-words2"); + if (picked_words != null) { + const list = picked_words.value.split(" "); for (let i = 0; i < list.length; ++i) { list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除字符串两边空字符 if (list[i] !== "" && "".indexOf(list[i]) === -1 && "".indexOf(list[i]) === -1) { @@ -35,8 +35,8 @@ function highLight() { } } } - if (sel_word2 != null) { - const list2 = sel_word2.value.split(" "); + if (dictionary_words != null) { + const list2 = dictionary_words.value.split(" "); for (let i = 0; i < list2.length; ++i) { list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, ""); if (list2[i] !== "" && "".indexOf(list2[i]) === -1 && "".indexOf(list2[i]) === -1) { @@ -49,11 +49,11 @@ function highLight() { } function cancel_highLight() { - const list = sel_word1.value.split(" "); + const list = picked_words.value.split(" "); let txt = document.getElementById("article").innerText; - let sel_word1 = document.getElementById("selected-words"); - const sel_word2 = document.getElementById("selected-words2"); - if (sel_word1 != null) { + let picked_words = document.getElementById("selected-words"); + const dictionary_words = document.getElementById("selected-words2"); + if (picked_words != null) { for (let i = 0; i < list.length; ++i) { list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); if (list[i] !== "") { @@ -61,10 +61,10 @@ function cancel_highLight() { } } } - if (sel_word2 != null) { - let list2 = sel_word1.value.split(" "); + if (dictionary_words != null) { + let list2 = picked_words.value.split(" "); for (let i = 0; i < list2.length; ++i) { - list2 = sel_word2.value.split(" "); + list2 = dictionary_words.value.split(" "); list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, ""); if (list2[i] !== "") { txt = txt.replace("" + list[i] + "", "list[i]");