From 8fb52915cab4e4e9096b1ccc1d27cfd84fa3e389 Mon Sep 17 00:00:00 2001 From: lixiaofeng <2368272960@qq.com> Date: Mon, 27 May 2024 22:46:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20app/static/js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/highlight.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index c9c3a02..f0680af 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -1,4 +1,4 @@ -let isHighlight = localStorage.getItem('highlightChecked') !== 'false'; // default to true +let isHighlight = true; function cancelBtnHandler() { cancelHighlighting(); @@ -25,7 +25,9 @@ function highLight() { let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器 let pickedWords = document.getElementById("selected-words"); // words picked to the text area let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list - let allWords = dictionaryWords === null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value; + let allWords = dictionaryWords == null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value; + highlightWords = document.getElementById("selected-words3"); + allWords = highlightWords == null ? allWords : allWords + " " + highlightWords.value; const list = allWords.split(" "); // 将所有的生词放入一个list中 let totalSet = new Set(); for (let i = 0; i < list.length; ++i) { @@ -39,16 +41,15 @@ function highLight() { } totalSet = new Set([...totalSet, ...matches]); } - } + } // 删除所有的mark标签,防止标签发生嵌套 articleContent = articleContent.replace(/<(mark)[^>]*>/gi, ""); articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, ""); - // 将文章中所有出现该单词word的地方改为:"" + word + ""。 + // 将文章中所有出现该单词word的地方改为:"" + word + ""。 for (let word of totalSet) { - articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "" + word + ""); + articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "" + word + ""); } document.getElementById("article").innerHTML = articleContent; - } function cancelHighlighting() { @@ -74,7 +75,6 @@ function toggleHighlighting() { isHighlight = true; highLight(); } - localStorage.setItem('highlightChecked', isHighlight); } showBtnHandler(); \ No newline at end of file -- 2.17.1 From 1929c5509a549b7519ed008612251830eec5d4d5 Mon Sep 17 00:00:00 2001 From: lixiaofeng <2368272960@qq.com> Date: Mon, 27 May 2024 22:46:47 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fillword.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 fillword.js diff --git a/fillword.js b/fillword.js new file mode 100644 index 0000000..f33a3bd --- /dev/null +++ b/fillword.js @@ -0,0 +1,43 @@ +let isRead = true; +let isChoose = true; +let highlightWords = ""; + +function getWord() { + return window.getSelection ? window.getSelection() : document.selection.createRange().text; +} + +function fillInWord() { + let word = getWord(); + if (isRead) Reader.read(word, inputSlider.value); + if (!isChoose) { + if(isHighlight){ + const element = document.getElementById("selected-words3"); + element.value = element.value + " " + word; + } + return; + } + const element = document.getElementById("selected-words"); + element.value = element.value + " " + word; +} + +document.getElementById("text-content").addEventListener("click", fillInWord, false); + +const sliderValue = document.getElementById("rangeValue"); +const inputSlider = document.getElementById("rangeComponent"); +inputSlider.oninput = () => { + let value = inputSlider.value; + sliderValue.textContent = value + '×'; +}; + +function onReadClick() { + isRead = !isRead; +} + +function onChooseClick() { + isChoose = !isChoose; +} + +// 如果网页刷新,停止播放声音 +if (performance.getEntriesByType("navigation")[0].type == "reload") { + Reader.stopRead(); +} \ No newline at end of file -- 2.17.1 From 9aa4dc1e386b051d955ad76f20df0c90ec7a7e82 Mon Sep 17 00:00:00 2001 From: lixiaofeng <2368272960@qq.com> Date: Mon, 27 May 2024 22:47:25 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20app/test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug546_lixiaofeng.py | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/test/test_bug546_lixiaofeng.py diff --git a/app/test/test_bug546_lixiaofeng.py b/app/test/test_bug546_lixiaofeng.py new file mode 100644 index 0000000..649aeba --- /dev/null +++ b/app/test/test_bug546_lixiaofeng.py @@ -0,0 +1,39 @@ +from selenium.webdriver.common.action_chains import ActionChains +from helper import signup + + +def test_highlight(driver, URL): + try: + # 打开网页 + driver.get(URL) + driver.maximize_window() + + # 注册 + signup(URL, driver) + + # 取消勾选“划词入库按钮” + highlight_checkbox = driver.find_element_by_id("test1") + driver.execute_script("arguments[0].click();", highlight_checkbox) + + article = driver.find_element_by_id("article") + + # 创建 ActionChains 对象 + actions = ActionChains(driver) + + # 移动鼠标到起点位置 + actions.move_to_element(article) + # actions.move_to_element_with_offset(article, 50, 100) + # 按下鼠标左键 + actions.click_and_hold() + # 拖动鼠标到结束位置 + actions.move_by_offset(400,50) + # 释放鼠标左键 + actions.release() + # 执行操作链 + actions.perform() + # time.sleep(10) + + assert driver.find_element_by_tag_name("mark") is not None + finally: + # 测试结束后关闭浏览器 + driver.quit() \ No newline at end of file -- 2.17.1 From 045352f8aa575fc2dc3671e8bb4e1f263d7f7a1b Mon Sep 17 00:00:00 2001 From: lixiaofeng <2368272960@qq.com> Date: Mon, 27 May 2024 22:47:58 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20app/templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/userpage_get.html | 64 ++++++--------------------------- 1 file changed, 11 insertions(+), 53 deletions(-) diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index edb8bf2..79031be 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -86,7 +86,7 @@ {{ today_article['source'] }} - + {{ today_article['question'] }}
{{ today_article['source'] }}
{{ today_article['question'] }}