Compare commits

...

24 Commits

Author SHA1 Message Date
包月琳 f40a968a17 删除 'Bug476-ZhangWeiHao-BaoYuelin' 2023-05-10 18:59:30 +08:00
包月琳 59a1fe607a 添加 'Bug476-ZhangWeiHao-BaoYuelin' 2023-05-10 18:55:48 +08:00
mrlan 43c719b6b2 Merge pull request 'Fix bug 501 - 特殊字符&加入生词库后删除按钮失效' (#81) from Bug501-Hui into master
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/81
2023-01-31 16:45:50 +08:00
Hui Lan a1955341c6 Fix bug 501 - 特殊字符&加入生词库后删除按钮失效 2023-01-31 16:39:11 +08:00
mrlan 92a8b4a994 Lanhui-update-README2 (#80)
Co-authored-by: Lan Hui <1348141770@qq.com>
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/80
Co-authored-by: mrlan <mrlan@noreply.121.4.94.30>
Co-committed-by: mrlan <mrlan@noreply.121.4.94.30>
2023-01-30 15:44:01 +08:00
王志豪 e10dbf9d67 Bug507-WuWenZhuo (#70)
### 修复了生词簿为空时,双击文章单词无法高亮的问题
通过增加一个判断,判断生词簿为空时,不把生词簿的内容进行处理,仅处理选中单词。

### 修复了生词簿为空时,取消高亮后,导致文章格式混乱的问题
原代码中,从数据库提取文章放到网页上时,使用的是.innerText的方法,导致原文章里包含的<br>标签丢失,导致文章格式混乱的问题。

Co-authored-by: unknown <Alcatraz@qq.com>
Co-authored-by: Hui Lan <lanhui@zjnu.edu.cn>
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/70
Co-authored-by: 王志豪 <1594799762@qq.com>
Co-committed-by: 王志豪 <1594799762@qq.com>
2023-01-29 12:48:52 +08:00
李雨峰 9cdc9c6f7f Bug521-LiYuFeng-Refactor (#72)
@mrlan
蓝老师:

    本次改进内容如下:
        1. 对生词居中问题进行修改,现在已经不会居中了。
        2. 对于单词数量基数大而导致的排序速度慢的问题,我们进行了优化,提升了排序的速度。
        3. 对用户交互进行了优化,当用户点击“熟悉”或“不熟悉”之后,会自动进行排序,并会跳转到那个单词的位置,用抖动的效果来提示用户。

Co-authored-by: isaac <1141730046@qq.com>
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/72
Co-authored-by: 李雨峰 <1141730046@qq.com>
Co-committed-by: 李雨峰 <1141730046@qq.com>
2023-01-29 12:01:19 +08:00
陈秋伟 972a1a5524 Bug490-ChenQiuwei (#63)
修复Bug-490,使注册时确认密码能够发挥作用,在确认密码与所设置密码不一致时,能够提示“确认密码与输入密码不一致”。

Co-authored-by: 2658626578 <2658626578@qq.com>
Co-authored-by: Hui Lan <lanhui@zjnu.edu.cn>
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/63
Co-authored-by: 陈秋伟 <2658626578@qq.com>
Co-committed-by: 陈秋伟 <2658626578@qq.com>
2023-01-29 11:49:27 +08:00
mrlan c52d53596f Merge pull request 'Bug489-DingRui' (#74) from SPM2022F-CONTRIBUTORS-DingRui into master
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/74
2023-01-29 11:31:41 +08:00
mrlan ca8c1bf8de Merge pull request 'Bug508-CenHaotian' (#62) from Bug508-CenHaotian into master
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/62
2023-01-29 11:19:49 +08:00
mrlan febd0fc932 Merge pull request '用简单的方法(创建 frequency 文件夹)修复Bug 499' (#64) from Bug499-Hui into master
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/64
2023-01-29 11:06:17 +08:00
mrlan 03353d49b1 Bug525-Hui (#79)
Co-authored-by: Hui Lan <lanhui@zjnu.edu.cn>
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/79
Co-authored-by: mrlan <mrlan@noreply.121.4.94.30>
Co-committed-by: mrlan <mrlan@noreply.121.4.94.30>
2023-01-29 10:57:58 +08:00
mrlan 1373df2a3e Merge pull request '增加单词默认勾选,并修改提示 Fix Bug 495 - Liang Li Gang' (#77) from Bug495-LiangLiGang into master
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/77
2023-01-29 10:27:22 +08:00
np1717 086dfcb6eb fix bug 489 2022-12-19 17:54:10 +08:00
任榆 f0afd5f40f Merge pull request 'Bug 512 - 文章朗读问题' (#59) from Bug512-RenYu into master
Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/59
2022-12-13 13:39:23 +08:00
任榆 5cc981b549 Merge branch 'master' into Bug512-RenYu 2022-12-13 13:28:48 +08:00
岑昊天 f37ea182f6 加入生词库过滤| 2022-12-06 17:02:59 +08:00
MR LAN 6327b11711 Made folder 'frequency' under folder 'static', and added a README file under folder 'frequency' 2022-12-06 16:06:13 +08:00
岑昊天 d58dacd71c 修复Bug508,解决带有特殊字符|的单词在文章中的高亮问题 2022-12-06 14:40:50 +08:00
丁锐 89c12337d5 在README中修改内容 2022-12-02 15:48:45 +08:00
梁立港 b65ffa6054 增加单词默认勾选,并修改提示 2022-12-01 21:04:12 +08:00
丁锐 7e3004a2e6 撤回操作 2022-11-29 16:55:48 +08:00
丁锐 3609421976 对确认密码部分保证有数据读入 2022-11-29 16:53:59 +08:00
任榆 5c85041135 Bug 512 - 文章朗读问题
在fillwowrd.js中添加了stopRead()函数,将其添加给对应按钮或超链接以终止朗读。
2022-11-25 15:42:37 +08:00
13 changed files with 252 additions and 70 deletions

View File

@ -11,15 +11,14 @@ Hui Lan <hui.lan@cantab.net>
EnglishPal allows the user to build his list of new English words EnglishPal allows the user to build his list of new English words
picked from articles selected for him according his vocabulary level. picked from articles selected for him to read according his vocabulary level. EnglishPal will determine a user's vocabulary level based on his picked words. After that, it will recommend articles for him to read, in order to booster his English vocabulary furthermore.
## Run it on a local machine ## Run on your own laptop
`python3 main.py` `python3 main.py`
Make sure you have the SQLite database file in `app/static` (see below). Make sure you have put the SQLite database file in the path `app/static` (see below).
## Run it as a Docker container ## Run it as a Docker container
@ -29,32 +28,32 @@ Assuming that docker has been installed and that you are a sudo user (i.e., sudo
`sudo ./build.sh` `sudo ./build.sh`
Open your favourite Internet browser and enter this URL address: `http://ip-address:90`. Open your favourite Internet browser and enter this URL address: `http://ip-address:90`. Note: you must update the variable `DEPLOYMENT_DIR` in `build.sh`.
### Explanation on the commands in build.sh ### Explanation on the commands in build.sh
My steps for deploying English on the server. My steps for deploying English on a Ubuntu server.
- ssh to ubuntu@118.*.*.118 - ssh to ubuntu@118.*.*.118
- cd to /home/lanhui/englishpal2/EnglishPal - cd to `/home/lanhui/englishpal2/EnglishPal`
- Stop all docker service: `sudo service docker restart`. If you know the docker container ID, then the above command is an overkill. Use the following command instead: `sudo docker stop ContainerID`. You could get all container IDs with the following command: `sudo docker ps` - Stop all docker service: `sudo service docker restart`. If you know the docker container ID, then the above command is an overkill. Use the following command instead: `sudo docker stop ContainerID`. You could get all container IDs with the following command: `sudo docker ps`
- Rebuild container. Run the following command to rebuild a docker image after the code gets updated: `sudo docker build -t englishpal .` - Rebuild container. Run the following command to rebuild a docker image each time after the source code gets updated: `sudo docker build -t englishpal .`
- Run the application: `sudo docker run -d -p 90:80 -v /home/lanhui/englishpal2/EnglishPal/app/static/frequency:/app/static/frequency -t englishpal`. If you use `sudo docker run -d -p 90:80 -t englishpal`, data will be lost after terminating the program. - Run the application: `sudo docker run -d -p 90:80 -v /home/lanhui/englishpal2/EnglishPal/app/static/frequency:/app/static/frequency -t englishpal`. If you use `sudo docker run -d -p 90:80 -t englishpal`, data will be lost after terminating the program. If you want to automatically restart the docker image after each system reboot, add the option `--restart=always` after `docker run`.
- Save space: `sudo docker system prune -a -f` - Save disk space: `sudo docker system prune -a -f`
`build.sh` contains all the above commands. Run "sudo ./build.sh" to rebuild and start the web application.
### Other useful docker commands #### Other useful docker commands
- `sudo docker ps -a` - `sudo docker ps -a`
- `sudo docker logs image_name`, where image_name could be obtained from `sudo docker ps`. - `sudo docker logs image_name`, where `image_name` could be obtained from `sudo docker ps`.
`build.sh` contains all the above commands. Run "sudo ./build.sh" to rebuild and run the web application.
@ -68,6 +67,10 @@ All articles are stored in the `article` table in a SQLite file called
To add articles, open and edit `app/static/wordfreqapp.db` using DB Browser for SQLite (https://sqlitebrowser.org). To add articles, open and edit `app/static/wordfreqapp.db` using DB Browser for SQLite (https://sqlitebrowser.org).
### Extending an account's expiry date
By default, an account's expiry is 30 days after first sign-up. To extend account's expiry date, open and edit `user` table in `app/static/wordfreqapp.db`. Simply update field `expiry_date`.
### Exporting the database ### Exporting the database
Export wordfreqapp.db to wordfreqapp.sql using the following commands: Export wordfreqapp.db to wordfreqapp.sql using the following commands:
@ -92,33 +95,31 @@ sqlite3 wordfreqapp.db`. Delete wordfreqapp.db first if it exists.
### Uploading wordfreqapp.db to the server ### Uploading wordfreqapp.db to the server
`pscp wordfreqapp.db lanhui@118.*.*.118:/home/lanhui/englishpal/app/static` `pscp wordfreqapp.db lanhui@118.*.*.118:/home/lanhui/englishpal2/EnglishPal/app/static`
## Feedback ## Feedback
We welcome feedback on EnglishPal. We welcome feedback on EnglishPal. Feedback examples:
### Respondent 1 ### Feedback 1
- "Need a phone app. I use phone a lot. You cannot ask students to use computers."
"Need a phone app. I use phone a lot. You cannot ask students to use computers." ### Feedback 2
Can take a picture for text. Automatic translation.
### Respondent 2
“成为会员”改成“注册” - “成为会员”改成“注册”
“登出”改成“退出” - “登出”改成“退出”
“收集生词吧”改成“生词收集栏” - “收集生词吧”改成“生词收集栏”
“不要自动显示下一篇” - 不要自动显示下一篇
需要有“上一篇”、“下一篇” - 需要有“上一篇”、“下一篇”按钮。
@ -137,7 +138,7 @@ EnglishPal's bugs and improvement suggestions are recorded in [Bugzilla](http://
- Usability testing - Usability testing
## Improvements made by contributors ## Improvements made by contributors (incomplete list)
### 朱文绮 ### 朱文绮
@ -159,7 +160,6 @@ too many words that they already know, on the other hand, it can
reduce unnecessary memory occupied by the database, in addition, it reduce unnecessary memory occupied by the database, in addition, it
can also improve the simplicity of the page. can also improve the simplicity of the page.
More information at: http://118.25.96.118/kanboard/?controller=TaskViewController&action=readonly&task_id=736&token=81a561da57ff7a172da17a480f0d421ff3bc69efbd29437daef90b1b8959
### 占健豪 ### 占健豪
@ -181,4 +181,14 @@ Demo video link: https://b23.tv/QuB77m
Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=215 Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=215
*Last modified on 2021-10-17*
### 丁锐
修复了以下漏洞
漏洞:新用户在创建账号时,不需要输入确定密码也可以注册成功,并且新账户可以正常使用。
Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=489
*Last modified on 2023-01-30*

View File

@ -1,6 +1,6 @@
import hashlib import hashlib
import string import string
from datetime import datetime from datetime import datetime, timedelta
from UseSqlite import InsertQuery, RecordQuery from UseSqlite import InsertQuery, RecordQuery
path_prefix = '/var/www/wordfreq/wordfreq/' path_prefix = '/var/www/wordfreq/wordfreq/'
@ -23,7 +23,7 @@ def verify_user(username, password):
def add_user(username, password): def add_user(username, password):
start_date = datetime.now().strftime('%Y%m%d') start_date = datetime.now().strftime('%Y%m%d')
expiry_date = '20221230' expiry_date = (datetime.now() + timedelta(days=30)).strftime('%Y%m%d') # will expire after 30 days
# 将用户名和密码一起加密,以免暴露不同用户的相同密码 # 将用户名和密码一起加密,以免暴露不同用户的相同密码
password = md5(username + password) password = md5(username + password)
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db') rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')

View File

@ -5,7 +5,6 @@ from Login import check_username_availability, verify_user, add_user, get_expiry
# 初始化蓝图 # 初始化蓝图
accountService = Blueprint("accountService", __name__) accountService = Blueprint("accountService", __name__)
### Sign-up, login, logout ### ### Sign-up, login, logout ###
@accountService.route("/signup", methods=['GET', 'POST']) @accountService.route("/signup", methods=['GET', 'POST'])
def signup(): def signup():
@ -20,6 +19,7 @@ def signup():
# POST方法需判断是否注册成功再根据结果返回不同的内容 # POST方法需判断是否注册成功再根据结果返回不同的内容
username = escape(request.form['username']) username = escape(request.form['username'])
password = escape(request.form['password']) password = escape(request.form['password'])
password2 = escape(request.form['password2'])
#! 添加如下代码为了过滤注册时的非法字符 #! 添加如下代码为了过滤注册时的非法字符
warn = WarningMessage(username) warn = WarningMessage(username)
@ -32,6 +32,8 @@ def signup():
return render_template('signup.html') return render_template('signup.html')
elif len(password.strip()) < 4: # 密码过短 elif len(password.strip()) < 4: # 密码过短
return '密码过于简单。' return '密码过于简单。'
elif password != password2:
return '确认密码与输入密码不一致!'
else: # 添加账户信息 else: # 添加账户信息
add_user(username, password) add_user(username, password)
verified = verify_user(username, password) verified = verify_user(username, password)
@ -48,6 +50,7 @@ def signup():
return '用户名密码验证失败。' return '用户名密码验证失败。'
@accountService.route("/login", methods=['GET', 'POST']) @accountService.route("/login", methods=['GET', 'POST'])
def login(): def login():
''' '''

View File

@ -0,0 +1,5 @@
This folder holds users' vocabulary files.
Each file ends with .pickle.
For example, mrlan.pickle is the vocabulary file for user mrlan.

View File

@ -62,3 +62,7 @@ function onReadClick() {
function onChooseClick() { function onChooseClick() {
isChoose = !isChoose; isChoose = !isChoose;
} }
function stopRead() {
reader.cancel();
}

View File

@ -22,13 +22,21 @@ function getWord() {
function highLight() { function highLight() {
if (!isHighlight) return; if (!isHighlight) return;
let articleContent = document.getElementById("article").innerText; let articleContent = document.getElementById("article").innerText; //将原来的.innerText改为.innerHtml使用innerText会把原文章中所包含的<br>标签去除,导致处理后的文章内容失去了原来的格式
let pickedWords = document.getElementById("selected-words"); // words picked to the text area 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 dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list
let allWords = pickedWords.value + " " + dictionaryWords.value; let allWords = ""; //初始化allWords的值避免进入判断后编译器认为allWords未初始化的问题
const list = allWords.split(" "); if(dictionaryWords != null){//增加一个判断检查生词本里面是否为空如果为空allWords只添加选中的单词
allWords = pickedWords.value + " " + dictionaryWords.value;
}
else{
allWords = pickedWords.value + " ";
}
const list = allWords.split(" ");//将所有的生词放入一个list中用于后续处理
for (let i = 0; i < list.length; ++i) { for (let i = 0; i < list.length; ++i) {
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除单词两边的空字符 list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除单词两边的空字符
list[i] = list[i].replace('|', "");
list[i] = list[i].replace('?', "");
if (list[i] !== "" && "<mark>".indexOf(list[i]) === -1 && "</mark>".indexOf(list[i]) === -1) { if (list[i] !== "" && "<mark>".indexOf(list[i]) === -1 && "</mark>".indexOf(list[i]) === -1) {
//将文章中所有出现该单词word的地方改为" <mark>" + word + "<mark> "。 正则表达式RegExp()中,"\\s"代表单词前后必须要有空格,以防止只对单词中的部分字符高亮的情况出现。 //将文章中所有出现该单词word的地方改为" <mark>" + word + "<mark> "。 正则表达式RegExp()中,"\\s"代表单词前后必须要有空格,以防止只对单词中的部分字符高亮的情况出现。
articleContent = articleContent.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " <mark>" + list[i] + "</mark> "); articleContent = articleContent.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " <mark>" + list[i] + "</mark> ");
@ -38,15 +46,15 @@ function highLight() {
} }
function cancelHighlighting() { function cancelHighlighting() {
let articleContent = document.getElementById("article").innerText; let articleContent = document.getElementById("article").innerText;//将原来的.innerText改为.innerHtml原因同上
let pickedWords = document.getElementById("selected-words"); let pickedWords = document.getElementById("selected-words");
const dictionaryWords = document.getElementById("selected-words2"); const dictionaryWords = document.getElementById("selected-words2");
const list = pickedWords.value.split(" "); const list = pickedWords.value.split(" ");
if (pickedWords != null) { if (pickedWords != null) {
for (let i = 0; i < list.length; ++i) { for (let i = 0; i < list.length; ++i) {
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");
if (list[i] !== "") { if (list[i] !== "") { //原来判断的代码中替换的内容为“list[i]”这个字符串这明显是错误的我们需要替换的是list[i]里的内容
articleContent = articleContent.replace("<mark>" + list[i] + "</mark>", "list[i]"); articleContent = articleContent.replace(new RegExp("<mark>"+list[i]+"</mark>", "g"), list[i]);
} }
} }
} }
@ -55,8 +63,8 @@ function cancelHighlighting() {
for (let i = 0; i < list2.length; ++i) { for (let i = 0; i < list2.length; ++i) {
list2 = dictionaryWords.value.split(" "); list2 = dictionaryWords.value.split(" ");
list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, ""); list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, "");
if (list2[i] !== "") { if (list2[i] !== "") { //原来代码中替换的内容为“list[i]”这个字符串这明显是错误的我们需要替换的是list[i]里的内容
articleContent = articleContent.replace("<mark>" + list[i] + "</mark>", "list[i]"); articleContent = articleContent.replace(new RegExp("<mark>"+list2[i]+"</mark>", "g"), list2[i]);
} }
} }
} }

View File

@ -7,12 +7,22 @@ function familiar(theWord) {
url:"/" + username + "/" + word + "/familiar", url:"/" + username + "/" + word + "/familiar",
success:function(response){ success:function(response){
let new_freq = freq - 1; let new_freq = freq - 1;
const allow_move = document.getElementById("move_dynamiclly").checked;
if (allow_move) {
if (new_freq <= 0) {
removeWord(theWord);
} else {
renderWord({ word: theWord, freq: new_freq });
}
} else {
if(new_freq <1) { if(new_freq <1) {
$("#p_" + theWord).remove(); $("#p_" + theWord).remove();
} else { } else {
$("#freq_" + theWord).text(new_freq); $("#freq_" + theWord).text(new_freq);
} }
} }
}
}); });
} }
@ -25,19 +35,139 @@ function unfamiliar(theWord) {
url:"/" + username + "/" + word + "/unfamiliar", url:"/" + username + "/" + word + "/unfamiliar",
success:function(response){ success:function(response){
let new_freq = parseInt(freq) + 1; let new_freq = parseInt(freq) + 1;
const allow_move = document.getElementById("move_dynamiclly").checked;
if (allow_move) {
renderWord({ word: theWord, freq: new_freq });
} else {
$("#freq_" + theWord).text(new_freq); $("#freq_" + theWord).text(new_freq);
} }
}
}); });
} }
function delete_word(theWord) { function delete_word(theWord) {
let username = $("#username").text(); let username = $("#username").text();
let word = $("#word_" + theWord).text(); let word = theWord.replace('&amp;', '&');
$.ajax({ $.ajax({
type:"GET", type:"GET",
url:"/" + username + "/" + word + "/del", url:"/" + username + "/" + word + "/del",
success:function(response){ success:function(response){
const allow_move = document.getElementById("move_dynamiclly").checked;
if (allow_move) {
removeWord(theWord);
} else {
$("#p_" + theWord).remove(); $("#p_" + theWord).remove();
} }
}
}); });
} }
/*
* interface Word {
* word: string,
* freq: number
* }
* */
/**
* 传入一个词频HTML元素将其解析为Word类型的对象
*/
function parseWord(element) {
const word = element
.querySelector("a.btn.btn-light[role=button]") // 获取当前词频元素的词汇元素
.innerText // 获取词汇值;
const freq = Number.parseInt(element.querySelector(`#freq_${word}`).innerText); // 获取词汇的数量
return {
word,
freq
};
}
/**
* 使用模板将传入的单词转换为相应的HTML字符串
*/
function wordTemplate(word) {
// 这个模板应当与 templates/userpage_get.html 中的 <p id='p_${word.word}' class="new-word" > ... </p> 保持一致
return `<p id='p_${word.word}' class="new-word" >
<a id="word_${word.word}" class="btn btn-light" href='http://youdao.com/w/eng/${word.word}/#keyfrom=dict2.index'
role="button">${word.word}</a>
( <a id="freq_${word.word}" title="${word.word}">${word.freq}</a> )
<a class="btn btn-success" onclick="familiar('${word.word}')" role="button">熟悉</a>
<a class="btn btn-warning" onclick="unfamiliar('${word.word}')" role="button">不熟悉</a>
<a class="btn btn-danger" onclick="delete_word('${word.word}')" role="button">删除</a>
</p>`;
}
/**
* 删除某一词频元素
* 此处word为词频元素对应的单词
*/
function removeWord(word) {
// 根据词频信息删除元素
word = word.replace('&amp;', '&');
const element_to_remove = document.getElementById(`p_${word}`);
if (element_to_remove != null) {
element_to_remove.remove();
}
}
function renderWord(word) {
const container = document.querySelector(".word-container");
// 删除原有元素
removeWord(word.word);
// 插入新元素
let inserted = false;
const new_element = elementFromString(wordTemplate(word));
for (const current of container.children) {
const cur_word = parseWord(current);
// 找到第一个词频比它小的元素,插入到这个元素前面
if (compareWord(cur_word, word) == -1) {
container.insertBefore(new_element, current);
inserted = true;
break;
}
}
// 当word就是词频最小的词时把他补回去
if (!inserted) {
container.appendChild(new_element);
}
// 让发生变化的元素抖动
new_element.classList.add("shaking");
// 移动到该元素
new_element.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
// 抖动完毕后删除抖动类
setTimeout(() => {
new_element.classList.remove("shaking");
}, 1600);
}
/**
* 从string中创建一个HTML元素并返回
*/
function elementFromString(string) {
const d = document.createElement('div');
d.innerHTML = string;
return d.children.item(0);
}
/**
* 对比两个单词
* 当first小于second时返回-1
* 当first等于second时返回0
* 当first大于second时返回1
*/
function compareWord(first, second) {
if (first.freq < second.freq) {
return -1;
}
if (first.freq > second.freq) {
return 1;
}
if (first.word < second.word) {
return -1;
}
if (first.word > second.word) {
return 1;
}
return 0;
}

View File

@ -5,7 +5,7 @@
<title>账号过期</title> <title>账号过期</title>
</head> </head>
<body> <body>
<p>您的账号{{ username }}过期</p> <p>您的账号过期(过期日 {{expiry_date}}</p>
<p>为了提高服务质量English Pal 收取会员费用, 每天1元。</p> <p>为了提高服务质量English Pal 收取会员费用, 每天1元。</p>
<p>请决定你要试用的时间长度,扫描下面支付宝二维码支付。 支付时请注明<i>English Pal Membership Fee</i>。 我们会于12小时内激活账号。</p> <p>请决定你要试用的时间长度,扫描下面支付宝二维码支付。 支付时请注明<i>English Pal Membership Fee</i>。 我们会于12小时内激活账号。</p>
<p><img src="static/donate-the-author-hidden.jpg" width="120px" alt="支付宝二维码" /></p> <p><img src="static/donate-the-author-hidden.jpg" width="120px" alt="支付宝二维码" /></p>

View File

@ -17,8 +17,8 @@ You're logged in already! <a href="/logout">Logout</a>.
<form action="/signup" method="POST"> <form action="/signup" method="POST">
<p><input type="username" name="username" placeholder="输入用户名" required="required" class="username"></p> <p><input type="username" name="username" placeholder="输入用户名" required="required" class="username"></p>
<p><input type="password" name="password" placeholder="输入密码" class="password"></p> <p><input type="password" name="password" placeholder="输入密码" required="required" class="password"></p>
<p><input type="password" name="password2" placeholder="确认密码" class="password"></p> <p><input type="password" name="password2" placeholder="确认密码" required="required" class="password" ></p>
<button type="submit" class="btn">注册</button> <button type="submit" class="btn">注册</button>
</form> </form>

View File

@ -19,6 +19,20 @@
{% endif %} {% endif %}
<title>EnglishPal Study Room for {{ username }}</title> <title>EnglishPal Study Room for {{ username }}</title>
<style>
.shaking {
animation: shakes 1600ms ease-in-out;
}
@keyframes shakes {
10%, 90% { transform: translate3d(-1px, 0, 0); }
20%, 50% { transform: translate3d(+2px, 0, 0); }
30%, 70% { transform: translate3d(-4px, 0, 0); }
40%, 60% { transform: translate3d(+4px, 0, 0); }
50% { transform: translate3d(-4px, 0, 0); }
}
</style>
</head> </head>
<body> <body>
<div class="container-fluid"> <div class="container-fluid">
@ -67,12 +81,19 @@
{% endif %} {% endif %}
{% if d_len > 0 %} {% if d_len > 0 %}
<p><b>我的生词簿</b></p> <p>
<b>我的生词簿</b>
<label for="move_dynamiclly">
<input type="checkbox" name="move_dynamiclly" id="move_dynamiclly" checked>
允许动态调整顺序
</label>
</p>
<a name="aaa"></a>
<div class="word-container">
{% for x in lst3 %} {% for x in lst3 %}
{% set word = x[0] %} {% set word = x[0] %}
{% set freq = x[1] %} {% set freq = x[1] %}
{% if session.get('thisWord') == x[0] and session.get('time') == 1 %} {% if session.get('thisWord') == x[0] and session.get('time') == 1 %}
<a name="aaa"></a>
{% endif %} {% endif %}
<p id='p_{{ word }}' class="new-word" > <p id='p_{{ word }}' class="new-word" >
<a id="word_{{ word }}" class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index' <a id="word_{{ word }}" class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'
@ -83,6 +104,7 @@
<a class="btn btn-danger" onclick="delete_word('{{ word }}')" role="button">删除</a> <a class="btn btn-danger" onclick="delete_word('{{ word }}')" role="button">删除</a>
</p> </p>
{% endfor %} {% endfor %}
</div>
<input id="selected-words2" type="hidden" value="{{ words }}"> <input id="selected-words2" type="hidden" value="{{ words }}">
{% endif %} {% endif %}
</div> </div>

View File

@ -20,7 +20,7 @@
<title>EnglishPal Study Room for {{username}}</title> <title>EnglishPal Study Room for {{username}}</title>
</head> </head>
<body> <body>
<p>勾选认识的单词</p> <p>取消勾选认识的单词</p>
<form method="post" action="/{{username}}/mark"> <form method="post" action="/{{username}}/mark">
<input type="submit" name="add-btn" value="加入我的生词簿"/> <input type="submit" name="add-btn" value="加入我的生词簿"/>
{% for x in lst %} {% for x in lst %}
@ -30,7 +30,7 @@
: :
<a href='http://youdao.com/w/eng/{{word}}/#keyfrom=dict2.index' title={{word}}>{{word}}</a> <a href='http://youdao.com/w/eng/{{word}}/#keyfrom=dict2.index' title={{word}}>{{word}}</a>
({{x[1]}}) ({{x[1]}})
<input type="checkbox" name="marked" value="{{word}}"> <input type="checkbox" name="marked" value="{{word}}" checked>
</p> </p>
{% endfor %} {% endfor %}

View File

@ -107,7 +107,7 @@ def userpage(username):
# 用户过期 # 用户过期
user_expiry_date = session.get('expiry_date') user_expiry_date = session.get('expiry_date')
if datetime.now().strftime('%Y%m%d') > user_expiry_date: if datetime.now().strftime('%Y%m%d') > user_expiry_date:
return render_template('expiry.html') return render_template('expiry.html', expiry_date=user_expiry_date)
# 获取session里的用户名 # 获取session里的用户名
username = session.get('username') username = session.get('username')

View File

@ -39,7 +39,7 @@ def file2str(fname):#文件转字符
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。 def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
special_characters = '_©~=+[]*&$%^@.,?!:;#()"“”—‘’' # 把里面的字符都去掉 special_characters = '\_©~<=>+-/[]*&$%^@.,?!:;#()"“”—‘’{}|' # 把里面的字符都去掉
for c in special_characters: for c in special_characters:
s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况 s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
s = s.replace('--', ' ') s = s.replace('--', ' ')