diff --git a/app/static/js/fillword.js b/app/static/js/fillword.js index b3a8b42..82f00ea 100644 --- a/app/static/js/fillword.js +++ b/app/static/js/fillword.js @@ -1,5 +1,5 @@ -let isRead = true; -let isChoose = true; +let isRead = localStorage.getItem('readChecked') !== 'false'; +let isChoose = localStorage.getItem('chooseChecked') !== 'false'; function getWord() { return window.getSelection ? window.getSelection() : document.selection.createRange().text; @@ -11,6 +11,7 @@ function fillInWord() { if (!isChoose) return; const element = document.getElementById("selected-words"); element.value = element.value + " " + word; + localStorage.setItem('selectedWords', element.value); } document.getElementById("text-content").addEventListener("click", fillInWord, false); @@ -24,13 +25,15 @@ inputSlider.oninput = () => { function onReadClick() { isRead = !isRead; + localStorage.setItem('readChecked', isRead); } function onChooseClick() { isChoose = !isChoose; + localStorage.setItem('chooseChecked', isChoose); } // 如果网页刷新,停止播放声音 if (performance.getEntriesByType("navigation")[0].type == "reload") { Reader.stopRead(); -} \ No newline at end of file +} diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index 76b4793..42d3aaf 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -1,4 +1,4 @@ -let isHighlight = true; +let isHighlight = localStorage.getItem('highlightChecked') !== 'false'; function cancelBtnHandler() { cancelHighlighting(); @@ -39,7 +39,7 @@ function highLight() { } totalSet = new Set([...totalSet, ...matches]); } - } + } // 删除所有的mark标签,防止标签发生嵌套 articleContent = articleContent.replace(/<(mark)[^>]*>/gi, ""); articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, ""); @@ -73,6 +73,7 @@ function toggleHighlighting() { isHighlight = true; highLight(); } + localStorage.setItem('highlightChecked', isHighlight); } showBtnHandler(); \ No newline at end of file diff --git a/app/static/wordfreqapp.db b/app/static/wordfreqapp.db new file mode 100644 index 0000000..312881a Binary files /dev/null and b/app/static/wordfreqapp.db differ diff --git a/app/templates/mainpage_get.html b/app/templates/mainpage_get.html index e96e8dc..5c57c91 100644 --- a/app/templates/mainpage_get.html +++ b/app/templates/mainpage_get.html @@ -34,9 +34,9 @@

粘贴1篇文章 (English only)

-
+
- +
{% if d_len > 0 %}

最常见的词

@@ -53,5 +53,20 @@ {% endfor %} {% endif %} + diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index 8c684b6..adadd58 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -86,7 +86,7 @@

{{ today_article['source'] }}


- +

{{ today_article['question'] }}


- {% endfor %} - {% endif %} + {{ yml['header'] | safe }} + {% if yml['css']['item'] %} + {% for css in yml['css']['item'] %} + + {% endfor %} + {% endif %} + {% if yml['js']['head'] %} + {% for js in yml['js']['head'] %} + + {% endfor %} + {% endif %} - EnglishPal Study Room for {{username}} + EnglishPal Study Room for {{username}} -
-

- - -

-
- - {% for x in lst %} - {% set word = x[0]%} -

- {{loop.index}} - : - {{word}} - ({{x[1]}}) - -

+
+

+ + +

+ + + {% for x in lst %} + {% set word = x[0]%} +

+ {{loop.index}} + : + {{word}} + ({{x[1]}}) + +

- {% endfor %} - - {{ yml['footer'] | safe }} - {% if yml['js']['bottom'] %} + {% endfor %} + + {{ yml['footer'] | safe }} + {% if yml['js']['bottom'] %} {% for js in yml['js']['bottom'] %} - + {% endfor %} - {% endif %} -
+ {% endif %} +
diff --git a/app/test/test_save_selected_words.py b/app/test/test_save_selected_words.py new file mode 100644 index 0000000..4dc5883 --- /dev/null +++ b/app/test/test_save_selected_words.py @@ -0,0 +1,98 @@ +import random +import string +import time + +from selenium import webdriver +from selenium.webdriver.support.wait import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +HOME_PAGE = "http://127.0.0.1:5000/" + +word = [] +uname = 'lanhui' +password = 'l0ve1t' +def has_punctuation(s): #用于检查单词是否包含标点符号 + return [c for c in s if c in string.punctuation] != [] + +def login(driver): + driver.get(HOME_PAGE) + assert 'English Pal - Learn English smartly!' in driver.page_source + # 登录 + login_elem = driver.find_element_by_link_text('登录') + login_elem.click() + + username_input = driver.find_element_by_id('username') + username_input.send_keys(uname) + + password_input = driver.find_element_by_id('password') + password_input.send_keys(password) + + login_btn = driver.find_element_by_xpath('//button[text()="登录"]') # 找到登录按钮 + login_btn.click() + + # 确保页面加载完 + try: + WebDriverWait(driver, 10).until( + EC.title_is("EnglishPal Study Room for " + uname) # 替换为实际的页面标题 + ) + except Exception as e: + print("页面加载失败:", e) + driver.quit() + exit() + assert 'EnglishPal Study Room for ' + uname in driver.title + +def test_save_selected_word(): + global word + # 调用本地chromedriver + driver = webdriver.Chrome(executable_path="C:\Program Files\Google\Chrome\Application\chromedriver.exe") + try: + login(driver) + #点击单词添加到已选单词列表 + # 获取文章内容 + elem = driver.find_element_by_id('text-content') + essay_content = elem.text + + #随机选择单词 长度不小于6个字符,并且不包含标点符号 + elem = driver.find_element_by_id('selected-words') + word = random.choice(essay_content.split()) + while 'font>' in word or 'br>' in word or 'p>' in word or len(word) < 6 or has_punctuation(word): + word = random.choice(essay_content.split()) + print(type(word)) #str + elem.send_keys(word) #单词输入到输入框 + + # 检查单词是否已成功添加到已选列表 + # 再次获取