Compare commits

...

42 Commits

Author SHA1 Message Date
Lan Hui eff0d01fa0 word_operation.js: Resolve conflict 2024-08-27 08:15:18 +08:00
mrlan 8f38e5fd87 Merge pull request 'Bug571-TongQi' (#166) from Bug571-TongQi into Alpha-snapshot20240618
Reviewed-on: #166
2024-08-27 08:03:04 +08:00
mrlan b39cf2e4fa Merge pull request 'Remove wordfreqapp.db from app/static' (#178) from Bug578-ChenChen2 into Alpha-snapshot20240618
Reviewed-on: #178
2024-08-27 07:59:02 +08:00
Lan Hui 6f4b91fd73 Remove wordfreqapp.db from app/static 2024-08-27 07:58:26 +08:00
mrlan 09beaff831 Merge pull request 'Bug578-ChenChen' (#167) from Bug578-ChenChen into Alpha-snapshot20240618
Reviewed-on: #167
2024-08-27 07:53:20 +08:00
Lan Hui ebfe7416e6 userpaget_get.html: Resolve conflict 2024-08-27 07:43:57 +08:00
mrlan 98027158b5 Merge pull request 'Bug577-JiangXueQin' (#163) from Bug577-JiangXueQin into Alpha-snapshot20240618
Reviewed-on: #163
2024-08-27 07:39:25 +08:00
Lan Hui 92a1af4222 userpaget_get.html: Resolve conflict 2024-08-27 07:39:04 +08:00
mrlan 79dff9a3b5 Merge pull request 'Bug576-XiaBaizhi' (#162) from Bug576-XiaBaizhi into Alpha-snapshot20240618
Reviewed-on: #162
2024-08-27 07:21:05 +08:00
Lan Hui bd4fb6846b userpaget_get.html: Do not disable the 'Next Article' button 2024-08-27 07:20:20 +08:00
Lan Hui 2e203699c0 userpaget_get.html: Resolve merge conflicts 2024-08-27 07:15:22 +08:00
mrlan d502b3f474 Merge pull request 'Bug564-JiangChao' (#152) from Bug564-JiangChao into Alpha-snapshot20240618
Reviewed-on: #152
2024-08-26 10:29:26 +08:00
Lan Hui 66899376c3 userpaget_get.html: Resolve merge conflicts 2024-08-26 10:27:43 +08:00
mrlan 6cc7f043da Merge pull request 'Bug572-ZhongYi2' (#159) from Bug572-ZhongYi2 into Alpha-snapshot20240618
Reviewed-on: #159
2024-08-26 10:05:45 +08:00
Lan Hui 1d80fa8886 userpaget_get.html: Resolve merge conflicts 2024-08-26 10:03:47 +08:00
mrlan dc3ef2bc9f Merge pull request 'Bug533-ZhangXuDong' (#161) from Bug533-ZhangXuDong into Alpha-snapshot20240618
Reviewed-on: #161
2024-08-26 09:49:38 +08:00
Lan Hui 9eac40493b userpaget_get.html and mainpage_gethtml: improve display information. 2024-08-26 09:49:00 +08:00
Lan Hui fe6a28a81d userpaget_get.html: Resolve merge conflicts 2024-08-26 09:41:53 +08:00
mrlan bf8bb1a6bc Merge pull request 'Bug568-SongHaiyan' (#158) from Bug568-SongHaiyan into Alpha-snapshot20240618
Reviewed-on: #158
2024-08-26 09:28:18 +08:00
mrlan 7a97e25b8c Merge pull request 'Bug567-YuZheChen' (#155) from Bug567-YuZheChen into Alpha-snapshot20240618
Reviewed-on: #155
2024-08-26 09:18:24 +08:00
宋海燕 794dcf399c fix Bug571 2024-07-04 19:22:20 +08:00
陈宇航 9bbd3a978d Fix bug 533 2024-07-04 15:37:37 +08:00
夏栢芝 6b3efad1dc Merge branch 'Alpha-snapshot20240618' of http://118.25.96.118:3000/mrlan/EnglishPal into Bug576-XiaBaizhi 2024-07-04 15:05:36 +08:00
陈晨 faf5ec14a4 Fix bug 578 2024-07-04 15:04:34 +08:00
“jxq” 70fc469f5e Fix bug 577 2024-07-04 15:03:31 +08:00
陈晨 9dab83219a Fix bug 578 2024-07-04 15:02:57 +08:00
“jxq” 7bf1a958b5 Fix bug 577 2024-07-04 15:01:22 +08:00
“jxq” 55eac68160 Merge branch 'Alpha-snapshot20240618' of http://118.25.96.118:3000/mrlan/EnglishPal into Bug577-JiangXueQin 2024-07-04 14:56:26 +08:00
“jxq” dc3fd67b02 解决合并冲突 2024-07-04 14:56:20 +08:00
Kikky666 02f3c4fdfa Fix bug 576-XiaBaizhi 2024-07-04 11:35:59 +08:00
钟埸 18472acd3d Fix bug 572 2024-07-04 11:04:38 +08:00
钟埸 75c96a60df 解决合并冲突 2024-07-04 11:00:17 +08:00
张旭东 5657d8d5ee Fix Bug533 2024-07-04 10:44:41 +08:00
张旭东 1f718e201f init 2024-07-04 10:18:47 +08:00
宋海燕 7cf9c7cf56 fix Bug568 2024-07-04 09:54:09 +08:00
Yzccc 6633df7b70 Fix bug 567 2024-07-04 09:33:30 +08:00
Yzccc ccf22af9df Fix bug 567 2024-07-04 09:29:55 +08:00
姜潮 3383e411ec Fix bug 564 添加注释版 2024-07-03 15:19:42 +08:00
姜潮 f4488672ec Merge branch 'Alpha-snapshot20240618' of http://118.25.96.118:3000/mrlan/EnglishPal into Bug564-JiangChao 2024-07-03 09:46:06 +08:00
姜潮 54d09469f5 修复Bug564 2024-07-02 16:19:24 +08:00
姜潮 4b06915dc4 解决合并冲突 2024-07-02 16:17:43 +08:00
李思楠 8cbc7c9a0c 修复快速点击下一页按钮点击频率过快时页面跳转到未知名页面 2024-05-24 22:00:08 +08:00
15 changed files with 6565 additions and 106 deletions

View File

@ -9,10 +9,32 @@ from flask import Flask, request, redirect, render_template, url_for, session, a
from difficulty import get_difficulty_level_for_user, text_difficulty_level, user_difficulty_level from difficulty import get_difficulty_level_for_user, text_difficulty_level, user_difficulty_level
from model.article import get_all_articles, get_article_by_id, get_number_of_articles from model.article import get_all_articles, get_article_by_id, get_number_of_articles
import logging import logging
import re
path_prefix = './' path_prefix = './'
db_path_prefix = './db/' # comment this line in deployment db_path_prefix = './db/' # comment this line in deployment
oxford_words_path='./db/oxford_words.txt'
def count_oxford_words(text, oxford_words):
words = re.findall(r'\b\w+\b', text.lower())
total_words = len(words)
oxford_word_count = sum(1 for word in words if word in oxford_words)
return oxford_word_count, total_words
def calculate_ratio(oxford_word_count, total_words):
if total_words == 0:
return 0
return oxford_word_count / total_words
def load_oxford_words(file_path):
oxford_words = {}
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
parts = line.strip().split()
word = parts[0]
pos = parts[1]
level = parts[2]
oxford_words[word] = {'pos': pos, 'level': level}
return oxford_words
def total_number_of_essays(): def total_number_of_essays():
return get_number_of_articles() return get_number_of_articles()
@ -86,6 +108,9 @@ def get_today_article(user_word_list, visited_articles):
today_article = None today_article = None
if d: if d:
oxford_words = load_oxford_words(oxford_words_path)
oxford_word_count, total_words = count_oxford_words(d['text'],oxford_words)
ratio = calculate_ratio(oxford_word_count,total_words)
today_article = { today_article = {
"user_level": '%4.1f' % user_level, "user_level": '%4.1f' % user_level,
"text_level": '%4.1f' % text_level, "text_level": '%4.1f' % text_level,
@ -94,7 +119,8 @@ def get_today_article(user_word_list, visited_articles):
"article_body": get_article_body(d['text']), "article_body": get_article_body(d['text']),
"source": d["source"], "source": d["source"],
"question": get_question_part(d['question']), "question": get_question_part(d['question']),
"answer": get_answer_part(d['question']) "answer": get_answer_part(d['question']),
"ratio" : ratio
} }
return visited_articles, today_article, result_of_generate_article return visited_articles, today_article, result_of_generate_article

View File

@ -79,18 +79,18 @@ def article():
"username": session.get("username"), "username": session.get("username"),
} }
if request.method == "POST":
if request.method == "GET":
try:
delete_id = int(request.args.get("delete_id", 0))
except:
return "Delete article ID must be integer!"
if delete_id: # delete article
delete_article_by_id(delete_id)
_update_context()
elif request.method == "POST":
data = request.form data = request.form
if "delete_id" in data:
try:
delete_id = int(data["delete_id"]) # 转成int型
delete_article_by_id(delete_id) # 根据id删除article
flash(f'Article ID {delete_id} deleted successfully.') # 刷新页首提示语
_update_context()
except ValueError:
flash('Invalid article ID for deletion.') # 刷新页首提示语
content = data.get("content", "") content = data.get("content", "")
source = data.get("source", "") source = data.get("source", "")
question = data.get("question", "") question = data.get("question", "")
@ -99,9 +99,9 @@ def article():
if level not in ['1', '2', '3', '4']: if level not in ['1', '2', '3', '4']:
return "Level must be between 1 and 4." return "Level must be between 1 and 4."
add_article(content, source, level, question) add_article(content, source, level, question)
_update_context()
title = content.split('\n')[0] title = content.split('\n')[0]
flash(f'Article added. Title: {title}') flash(f'Article added. Title: {title}')
_update_context() # 这行应在flash之后 否则会发生新建的文章即点即删
return render_template("admin_manage_article.html", **context) return render_template("admin_manage_article.html", **context)

5942
app/db/oxford_words.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -79,6 +79,19 @@ def mainpage():
根据GET或POST方法来返回不同的主界面 根据GET或POST方法来返回不同的主界面
:return: 主界面 :return: 主界面
''' '''
article_text = get_all_articles()
texts = [item['text'] for item in article_text]
oxford_words = load_oxford_words(oxford_words_path)
# 提取所有单词
all_words = []
for text in texts:
words = re.findall(r'\b\w+\b', text.lower())
all_words.extend(words)
oxford_word_count = sum(1 for word in all_words if word in oxford_words)
ratio = calculate_ratio(oxford_word_count, len(all_words))
if request.method == 'POST': # when we submit a form if request.method == 'POST': # when we submit a form
content = escape(request.form['content']) content = escape(request.form['content'])
f = WordFreq(content) f = WordFreq(content)
@ -102,7 +115,8 @@ def mainpage():
d_len=d_len, d_len=d_len,
lst=lst, lst=lst,
yml=Yaml.yml, yml=Yaml.yml,
number_of_essays=number_of_essays) number_of_essays=number_of_essays,
ratio = ratio)
if __name__ == '__main__': if __name__ == '__main__':

37
app/static/css/button.css Normal file
View File

@ -0,0 +1,37 @@
/* 按钮(上一篇,下一篇)样式 */
.pagination {
padding: 20px;
max-width: 600px;
}
.arrow {
margin-right: 15px;
display: flex;
align-items: center;
background: #007BFF; /* 按钮背景颜色 */
border: none;
color: #FFF; /* 按钮文字颜色 */
padding: 5px 12px;
font-size: 20px;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.arrow i {
margin: 0 5px;
}
.arrow:hover {
background-color: #0056b3; /* 按钮悬停时的背景颜色 */
cursor: pointer;
}
.arrow:focus {
outline: none;
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.5);
}
/* 为首页时按钮(Pre Article)的背景颜色 */
.gray-background {
background-color: #6c757d !important;
}

View File

@ -0,0 +1,52 @@
#slider {
margin: 20px auto;
width: 200px;
height: 40px;
position: relative;
border-radius: 5px;
background-color: #dae2d0;
overflow: hidden;
text-align: center;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
}
#slider_bg {
position: absolute;
left: 0;
top: 0;
height: 100%;
background-color: #7AC23C;
z-index: 1;
}
#label {
width: 46px;
position: absolute;
left: 0;
top: 0;
height: 38px;
line-height: 38px;
border: 1px solid #cccccc;
background: #fff;
z-index: 3;
cursor: move;
color: #ff9e77;
font-size: 16px;
font-weight: 900;
}
#labelTip {
position: absolute;
left: 0;
width: 100%;
height: 100%;
font-size: 13px;
font-family: 'Microsoft Yahei', serif;
color: #787878;
line-height: 38px;
text-align: center;
z-index: 2;
}

5
app/static/js/jquery-1.12.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,200 @@
/**
* jquery plugin -- jquery.slideunlock.js
* Description: a slideunlock plugin based on jQuery
* Version: 1.1
* Author: Dong Yuhao
* created: March 27, 2016
*/
;(function ($,window,document,undefined) {
function SliderUnlock(elm, options, success){
var me = this;
var $elm = me.checkElm(elm) ? $(elm) : $;
success = me.checkFn(success) ? success : function(){};
var opts = {
successLabelTip: "Successfully Verified",
duration: 200,
swipestart: false,
min: 0,
max: $elm.width(),
index: 0,
isOk: false,
lableIndex: 0
};
opts = $.extend(opts, options||{});
//$elm
me.elm = $elm;
//opts
me.opts = opts;
//是否开始滑动
me.swipestart = opts.swipestart;
//最小值
me.min = opts.min;
//最大值
me.max = opts.max;
//当前滑动条所处的位置
me.index = opts.index;
//是否滑动成功
me.isOk = opts.isOk;
//滑块宽度
me.labelWidth = me.elm.find('#label').width();
//滑块背景
me.sliderBg = me.elm.find('#slider_bg');
//鼠标在滑动按钮的位置
me.lableIndex = opts.lableIndex;
//success
me.success = success;
}
SliderUnlock.prototype.init = function () {
var me = this;
me.updateView();
me.elm.find("#label").on("mousedown", function (event) {
var e = event || window.event;
me.lableIndex = e.clientX - this.offsetLeft;
me.handerIn();
}).on("mousemove", function (event) {
me.handerMove(event);
}).on("mouseup", function (event) {
me.handerOut();
}).on("mouseout", function (event) {
me.handerOut();
}).on("touchstart", function (event) {
var e = event || window.event;
me.lableIndex = e.originalEvent.touches[0].pageX - this.offsetLeft;
me.handerIn();
}).on("touchmove", function (event) {
me.handerMove(event, "mobile");
}).on("touchend", function (event) {
me.handerOut();
});
};
SliderUnlock.prototype.getIsOk = function() {
return this.isOk;
};
/**
* 鼠标/手指接触滑动按钮
*/
SliderUnlock.prototype.handerIn = function () {
var me = this;
me.swipestart = true;
me.min = 0;
me.max = me.elm.width();
};
/**
* 鼠标/手指移出
*/
SliderUnlock.prototype.handerOut = function () {
var me = this;
//停止
me.swipestart = false;
//me.move();
if (me.index < me.max) {
me.reset();
}
};
/**
* 鼠标/手指移动
* @param event
* @param type
*/
SliderUnlock.prototype.handerMove = function (event, type) {
var me = this;
if (me.swipestart) {
event.preventDefault();
event = event || window.event;
if (type == "mobile") {
me.index = event.originalEvent.touches[0].pageX - me.lableIndex;
} else {
me.index = event.clientX - me.lableIndex;
}
me.move();
}
};
/**
* 鼠标/手指移动过程
*/
SliderUnlock.prototype.move = function () {
var me = this;
if ((me.index + me.labelWidth) >= me.max) {
me.index = me.max - me.labelWidth -2;
//停止
me.swipestart = false;
//解锁
me.isOk = true;
}
if (me.index < 0) {
me.index = me.min;
//未解锁
me.isOk = false;
}
if (me.index+me.labelWidth+2 == me.max && me.max > 0 && me.isOk) {
//解锁默认操作
$('#label').unbind().next('#labelTip').
text(me.opts.successLabelTip).css({'color': '#fff'});
me.success();
}
me.updateView();
};
/**
* 更新视图
*/
SliderUnlock.prototype.updateView = function () {
var me = this;
me.sliderBg.css('width', me.index);
me.elm.find("#label").css("left", me.index + "px")
};
/**
* 重置slide的起点
*/
SliderUnlock.prototype.reset = function () {
var me = this;
me.index = 0;
me.sliderBg .animate({'width':0},me.opts.duration);
me.elm.find("#label").animate({left: me.index}, me.opts.duration)
.next("#lableTip").animate({opacity: 1}, me.opts.duration);
me.updateView();
};
/**
* 检测元素是否存在
* @param elm
* @returns {boolean}
*/
SliderUnlock.prototype.checkElm = function (elm) {
if($(elm).length > 0){
return true;
}else{
throw "this element does not exist.";
}
};
/**
* 检测传入参数是否是function
* @param fn
* @returns {boolean}
*/
SliderUnlock.prototype.checkFn = function (fn) {
if(typeof fn === "function"){
return true;
}else{
throw "the param is not a function.";
}
};
window['SliderUnlock'] = SliderUnlock;
})(jQuery, window, document);

View File

@ -68,6 +68,7 @@ function read_word(theWord) {
Reader.read(to_speak, inputSlider.value); Reader.read(to_speak, inputSlider.value);
} }
/* /*
* interface Word { * interface Word {
* word: string, * word: string,
@ -102,19 +103,12 @@ function wordTemplate(word) {
<a class="btn btn-warning" onclick="unfamiliar('${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> <a class="btn btn-danger" onclick="delete_word('${word.word}')" role="button">删除</a>
<a class="btn btn-info" onclick="read_word('${word.word}')" role="button">朗读</a> <a class="btn btn-info" onclick="read_word('${word.word}')" role="button">朗读</a>
<a class="btn btn-primary" onclick="addNote('{{ word }}'); saveNote('{{ word }}')" role="button">笔记</a> <!-- Modify to call addNote and then saveNote -->
<input type="text" id="note_{{ word }}" class="note-input" placeholder="输入笔记内容" style="display:none;" oninput="saveNote('{{ word }}')"> <!-- Added oninput event -->
</p>`; </p>`;
} }
/**
* 使用模板将传入的单词转换为相应的HTML字符串
*/
function wordTemplate(word) {
// 这个模板应当与 templates/userpage_get.html 中的 <p id='p_${word.word}' class="new-word" > ... </p> 保持一致
return ``;
}
/** /**
* 删除某一词频元素 * 删除某一词频元素
* 此处word为词频元素对应的单词 * 此处word为词频元素对应的单词
@ -183,6 +177,27 @@ function compareWord(first, second) {
return 0; return 0;
} }
/* 生词csv导出 */
function exportToCSV() {
let csvContent = "data:text/csv;charset=utf-8,Word,Frequency\n";
let rows = document.querySelectorAll(".new-word");
rows.forEach(row => {
let word = row.querySelector("a.btn-light").innerText;
let freq = row.querySelector("a[title]").innerText;
csvContent += word + "," + freq + "\n";
});
let encodedUri = encodeURI(csvContent);
let link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "word_list.csv");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
/** /**
* *
* 随机选取 10 个单词学习 * 随机选取 10 个单词学习
@ -215,6 +230,6 @@ function random_select_word(word) {
} else { } else {
p.style.display = 'none'; p.style.display = 'none';
} }
}) });
} }
} }

View File

@ -7,6 +7,11 @@
content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" /> content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" />
<meta name="format-detection" content="telephone=no" /> <meta name="format-detection" content="telephone=no" />
<link href="../static/css/bootstrap.css" rel="stylesheet"> <link href="../static/css/bootstrap.css" rel="stylesheet">
<script>
function confirmDeletion(articleId, articleTitle) {
return confirm(`确认删除文章 "${articleTitle}" (ID: ${articleId}) 吗?`);
}
</script>
</head> </head>
<body class="container" style="width: 800px; margin: auto; margin-top:24px;"> <body class="container" style="width: 800px; margin: auto; margin-top:24px;">
@ -66,9 +71,10 @@
<div class="list-group"> <div class="list-group">
{% for text in text_list %} {% for text in text_list %}
<div class="list-group-item list-group-item-action" aria-current="true"> <div class="list-group-item list-group-item-action" aria-current="true">
<div> <form action="/admin/article" method="post" style="display: inline;">
<a type="button" href="/admin/article?delete_id={{text.article_id}}" class="btn btn-outline-danger btn-sm">删除</a> <input type="hidden" name="delete_id" value="{{ text.article_id }}">
</div> <button type="submit" class="btn btn-outline-danger btn-sm" onclick="return confirmDeletion('{{ text.article_id }}', '{{ text.title }}')">删除</button>
</form>
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ text.title }}</h5> <h5 class="mb-1">{{ text.title }}</h5>
</div> </div>

View File

@ -31,7 +31,7 @@
<p><a href="/login">登录</a> <a href="/signup">注册</a> <a href="/static/usr/instructions.html">使用说明</a></p > <p><a href="/login">登录</a> <a href="/signup">注册</a> <a href="/static/usr/instructions.html">使用说明</a></p >
<p><b> {{ random_ads }}。 <a href="/signup">试试</a>吧!</b></p> <p><b> {{ random_ads }}。 <a href="/signup">试试</a>吧!</b></p>
{% endif %} {% endif %}
<div class="alert alert-success" role="alert">共有文章 <span class="badge bg-success"> {{ number_of_essays }} </span></div> <div class="alert alert-success" role="alert">共有文章 <span class="badge bg-success"> {{ number_of_essays }} </span>,覆盖 <span class="badge bg-success"> {{ (ratio * 100) | int }}% </span> 的 Oxford5000 单词</div>
<p>粘贴1篇文章 (English only)</p> <p>粘贴1篇文章 (English only)</p>
<form method="post" action="/"> <form method="post" action="/">
<textarea name="content" id="article" rows="10" cols="120"></textarea><br/> <textarea name="content" id="article" rows="10" cols="120"></textarea><br/>

View File

@ -1,72 +1,107 @@
{% block body %} {% block body %}
{% if session['logged_in'] %} {% if session['logged_in'] %}
You're logged in already! <a href="/logout">Logout</a>.
You're logged in already! <a href="/logout">Logout</a>.
{% else %} {% else %}
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" />
<link rel="stylesheet" href="static/css/login_service.css"> <link rel="stylesheet" href="static/css/login_service.css">
<script src="static/js/jquery.js"></script> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge,chrome=1">
<link href="static/css/slide-unlock.css" rel="stylesheet">
<script src="static/js/jquery.js"></script>
<script src="static/js/jquery.slideunlock.js"></script>
<script> <script>
function signup() { var slider
let username = $("#username").val(); let username,password,password2
let password = $("#password").val(); $(document).ready(function() {
let password2 = $("#password2").val(); slider = new SliderUnlock("#slider", {
if (username === "" || password === "" || password2 === ""){ successLabelTip: "验证成功"
alert('输入不能为空!'); }, function() {
return false;
} });
if (password.includes(' ') || password2.includes(' ')) { slider.init(); // 初始化滑块解锁功能
alert('输入不能包含空格!'); });
return false;
} function signup(){
if (password !== password2) { // 发起 AJAX 请求来处理注册
alert('确认密码与输入密码不一致!'); username = $("#username").val().trim();
return false; password = $("#password").val().trim();
} password2 = $("#password2").val().trim();
if (password.length < 4) {
alert('密码过于简单。(密码长度至少4位)'); // 基本表单验证
return false; if (username === "" || password === "" || password2 === "") {
} alert('输入不能为空!');
$.post("/signup", {'username': username, 'password': password},
function (response) {
if (response.status === '0') {
alert('用户名'+username+'已经被注册。');
window.location.href = "/signup";
} else if (response.status === '1') {
alert('用户名密码验证失败。');
window.location.href = "/signup";
} else if (response.status === '2') {
let f = confirm("恭喜,你已成功注册,你的用户名是"+username+'.\n点击“确认”开始使用或点击“取消”返回首页');
if (f) {
window.location.href = '/'+username+'/userpage';
} else {
window.location.href = '/';
}
} else if (response.status === '3') {
alert(response.warn);
}
}
)
return false; return false;
} }
if (password.includes(' ') || password2.includes(' ')) {
alert('输入不能包含空格!');
return false;
}
if (password !== password2) {
alert('确认密码与输入密码不一致!');
return false;
}
if (password.length < 4) {
alert('密码过于简单。(密码长度至少4位)');
return false;
}
is_ok = slider.getIsOk();
if(!is_ok){
alert('没有滑动验证');
return false;
}
$.post("/signup", {
'username': username,
'password': password
}, function(response) {
if (response.status === '0') {
alert('用户名' + username + '已经被注册。');
window.location.href = "/signup";
} else if (response.status === '1') {
alert('用户名密码验证失败。');
window.location.href = "/signup";
} else if (response.status === '2') {
var f = confirm("恭喜,你已成功注册,你的用户名是" + username + '.\n点击“确认”开始使用或点击“取消”返回首页');
if (f) {
window.location.href = '/' + username + '/userpage';
} else {
window.location.href = '/';
}
} else if (response.status === '3') {
alert(response.warn);
}
});
return false;
}
</script>
<p>{{ get_flashed_messages()[0] | safe }}</p>
<div class="container">
<section class="signin-heading">
<h1>Sign up</h1>
</section>
<form>
<p><input type="text" id="username" placeholder="输入用户名" class="username"></p>
<p><input type="password" id="password" placeholder="输入密码" class="password"></p>
<p><input type="password" id="password2" placeholder="确认密码" class="password"></p>
<div id="slider">
<div id="slider_bg"></div>
<span id="label">>></span> <span id="labelTip">-----滑动验证你是不是人类</span>
</div>
<button type="button" class="btn" onclick="signup()">注册</button>
</form>
</div>
<script>
// Bind click event to the signup button
$(".btn").click(function() {
// Trigger slider unlock
var slider = new SliderUnlock("#slider");
slider.isOk();
});
</script> </script>
<p>{{ get_flashed_messages()[0] | safe }}</p>
<div class="container">
<section class="signin-heading">
<h1>Sign up</h1>
</section>
<p><input type="username" id="username" placeholder="输入用户名" class="username"></p>
<p><input type="password" id="password" placeholder="输入密码" class="password"></p>
<p><input type="password" id="password2" placeholder="确认密码" class="password" ></p>
<button type="button" class="btn" onclick="signup()">注册</button>
</div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
@ -6,6 +6,8 @@
content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes"/> content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes"/>
<meta name="format-detection" content="telephone=no"/> <meta name="format-detection" content="telephone=no"/>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link rel="stylesheet" href="../static/css/button.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"></script>
{{ yml['header'] | safe }} {{ yml['header'] | safe }}
@ -71,15 +73,20 @@
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div> </div>
{% endfor %} {% endfor %}
<div class="pagination">
<button class="arrow" id="load_next_article" onclick="load_next_article();Reader.stopRead()" title="下一篇 Next Article"></button> <button class="arrow" id="load_pre_article" onclick="load_pre_article();Reader.stopRead()" title="Previous Article">
<button class="arrow" id="load_pre_article" onclick="load_pre_article();Reader.stopRead()" style="display: none" title="上一篇 Previous Article"></button> <i class="fas fa-chevron-left"></i> 上一篇
</button>
<button class="arrow" id="load_next_article" onclick="load_next_article();Reader.stopRead()" title="Next Article">
下一篇 <i class="fas fa-chevron-right"></i>
</button>
</div>
<p><b>阅读文章并回答问题</b></p> <p><b>阅读文章并回答问题</b></p>
<div id="text-content"> <div id="text-content">
<div id="found"> <div id="found">
<div class="alert alert-success" role="alert">According to your word list, your level is <span class="text-decoration-underline" id="user_level">{{ today_article["user_level"] }}</span> and we have chosen an article with a difficulty level of <span class="text-decoration-underline" id="text_level">{{ today_article["text_level"] }}</span> for you.</div> <div class="alert alert-success" role="alert">According to your word list, your level is <span class="text-decoration-underline" id="user_level">{{ today_article["user_level"] }}</span> and we have chosen an article with a difficulty level of <span class="text-decoration-underline" id="text_level">{{ today_article["text_level"] }}</span> for you. The Oxford word coverage is <span class="text-decoration-underline" id="ratio">{{ (today_article["ratio"] * 100) | int }}%.</span></div>
<p class="text-muted" id="date">Article added on: {{ today_article["date"] }}</p><br/> <p class="text-muted" id="date">Article added on: {{ today_article["date"] }}</p><br/>
<div class="p-3 mb-2 bg-light text-dark" style="margin: 0 0.5%;"><br/> <div class="p-3 mb-2 bg-light text-dark" style="margin: 0 0.5%;"><br/>
<p class="display-6" id="article_title">{{ today_article["article_title"] }}</p><br/> <p class="display-6" id="article_title">{{ today_article["article_title"] }}</p><br/>
<p class="lead"><font id="article">{{ today_article["article_body"] }}</font></p><br/> <p class="lead"><font id="article">{{ today_article["article_body"] }}</font></p><br/>
@ -149,6 +156,8 @@
<a class="btn btn-primary btn-lg" onclick="random_select_word('{{ word }}')" role="button">随机选取10个</a> <a class="btn btn-primary btn-lg" onclick="random_select_word('{{ word }}')" role="button">随机选取10个</a>
<a class="btn btn-primary btn-lg" onclick="location.reload();" role="button">显示所有生词</a> <a class="btn btn-primary btn-lg" onclick="location.reload();" role="button">显示所有生词</a>
</p> </p>
<!--添加导出按钮-->
<button class="btn btn-primary" onclick="exportToCSV()">导出</button>
<a name="aaa"></a> <a name="aaa"></a>
<div class="word-container"> <div class="word-container">
{% for x in lst3 %} {% for x in lst3 %}
@ -164,19 +173,43 @@
<a class="btn btn-warning" onclick="unfamiliar('{{ word }}')" role="button">不熟悉</a> <a class="btn btn-warning" onclick="unfamiliar('{{ word }}')" role="button">不熟悉</a>
<a class="btn btn-danger" onclick="delete_word('{{ word }}')" role="button">删除</a> <a class="btn btn-danger" onclick="delete_word('{{ word }}')" role="button">删除</a>
<a class="btn btn-info" onclick="read_word('{{ word }}')" role="button">朗读</a> <a class="btn btn-info" onclick="read_word('{{ word }}')" role="button">朗读</a>
<a class="btn btn-primary" onclick="addNote('{{ word }}'); saveNote('{{ word }}')" role="button">笔记</a> <!-- Modify to call addNote and then saveNote -->
<input type="text" id="note_{{ word }}" class="note-input" placeholder="输入笔记内容" style="display:none;" oninput="saveNote('{{ word }}')"> <!-- Added oninput event -->
</p> </p>
{% endfor %} {% endfor %}
</div> </div>
<input id="selected-words2" type="hidden" value="{{ words }}"> <input id="selected-words2" type="hidden" value="{{ words }}">
{% endif %} {% endif %}
</div> </div>
<label id="selected-words3" type="hidden"></label>
{{ yml['footer'] | safe }} {{ yml['footer'] | safe }}
{% if yml['js']['bottom'] %} {% if yml['js']['bottom'] %}
{% for js in yml['js']['bottom'] %} {% for js in yml['js']['bottom'] %}
<script src="{{ js }}"></script> <script src="{{ js }}"></script>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<script type="text/javascript">
// Function to show/hide note input and load saved note content from localStorage
function addNote(word) {
var noteInput = document.getElementById("note_" + word);
var savedNote = localStorage.getItem(word); // Get the saved note from localStorage
if (savedNote) {
noteInput.value = savedNote; // Set the saved note if it exists
}
noteInput.style.display = (noteInput.style.display === 'none') ? 'inline-block' : 'none'; // Toggle display
}
// Example function to save the note to localStorage
function saveNote(word) {
var noteContent = document.getElementById("note_" + word).value;
localStorage.setItem(word, noteContent); // Save the note content in localStorage
console.log('Note saved for ' + word + ': ' + noteContent); // Log for debugging purposes
}
</script>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function () { // 页面加载时执行 window.onload = function () { // 页面加载时执行
const settings = { const settings = {
@ -202,11 +235,12 @@
elements.chooseCheckbox.checked = settings.chooseChecked; elements.chooseCheckbox.checked = settings.chooseChecked;
elements.rangeComponent.value = settings.rangeValue; elements.rangeComponent.value = settings.rangeValue;
elements.rangeValueDisplay.textContent = `${settings.rangeValue}x`; elements.rangeValueDisplay.textContent = `${settings.rangeValue}x`;
elements.selectedWordsInput.value = settings.selectedWords; <!-- elements.selectedWordsInput.value = settings.selectedWords;-->
// 刷新页面或进入页面时判断,若不是首篇文章,则上一篇按钮可见
if (sessionStorage.getItem('pre_page_button') !== 'display' && sessionStorage.getItem('pre_page_button')) { // 刷新页面或进入页面时判断,若是首篇文章,则颜色为灰色
$('#load_pre_article').show(); if (sessionStorage.getItem('pre_page_button') === 'display' || !sessionStorage.getItem('pre_page_button')) {
$('#load_pre_article').addClass('gray-background');
} }
// 事件监听器 // 事件监听器
@ -234,6 +268,9 @@
success: function(data) { success: function(data) {
// 更新页面内容 // 更新页面内容
if(data['today_article']){ if(data['today_article']){
// answer不可见
const e = document.getElementById('answer');
e.style.display = 'none';
update(data['today_article']); update(data['today_article']);
check_pre(data['visited_articles']); check_pre(data['visited_articles']);
check_next(data['result_of_generate_article']); check_next(data['result_of_generate_article']);
@ -248,6 +285,9 @@
success: function(data) { success: function(data) {
// 更新页面内容 // 更新页面内容
if(data['today_article']){ if(data['today_article']){
// answer不可见
const e = document.getElementById('answer');
e.style.display = 'none';
update(data['today_article']); update(data['today_article']);
check_pre(data['visited_articles']); check_pre(data['visited_articles']);
} }
@ -263,18 +303,18 @@
$('#source').html(today_article['source']); $('#source').html(today_article['source']);
$('#question').html(today_article["question"]); $('#question').html(today_article["question"]);
$('#answer').html(today_article["answer"]); $('#answer').html(today_article["answer"]);
$('#ratio').html(Math.round(today_article["ratio"] * 100) + '%');
document.querySelector('#text_level').classList.add('mark'); // highlight text difficult level for 2 seconds document.querySelector('#text_level').classList.add('mark'); // highlight text difficult level for 2 seconds
setTimeout(() => {document.querySelector('#text_level').classList.remove('mark');}, 2000); setTimeout(() => {document.querySelector('#text_level').classList.remove('mark');}, 2000);
document.querySelector('#user_level').classList.add('mark'); // do the same thing for user difficulty level document.querySelector('#user_level').classList.add('mark'); // do the same thing for user difficulty level
setTimeout(() => {document.querySelector('#user_level').classList.remove('mark');}, 2000); setTimeout(() => {document.querySelector('#user_level').classList.remove('mark');}, 2000);
} }
<!-- 检查是否存在上一篇或下一篇,不存在则对应按钮隐藏-->
function check_pre(visited_articles){ function check_pre(visited_articles){
if((visited_articles=='')||(visited_articles['index']<=0)){ if((visited_articles=='')||(visited_articles['index']<=0)){
$('#load_pre_article').hide(); $('#load_pre_article').addClass('gray-background'); // 设置为灰色
sessionStorage.setItem('pre_page_button', 'display') sessionStorage.setItem('pre_page_button', 'display')
}else{ }else{
$('#load_pre_article').show(); $('#load_pre_article').removeClass('gray-background'); // 设置为正常蓝色
sessionStorage.setItem('pre_page_button', 'show') sessionStorage.setItem('pre_page_button', 'show')
} }
} }

View File

@ -46,5 +46,7 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</div> </div>
<script>window.history.replaceState(null, null, window.location.href);
</script>
</body> </body>
</html> </html>

View File

@ -0,0 +1,85 @@
''' Contributed by Lin Junhong et al. 2023-06.'''
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException
import random, time
import string
# 初始化webdriver
# driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME)
# driver.implicitly_wait(10)
driver = webdriver.Chrome("C:\\Users\\12993\AppData\Local\Programs\Python\Python38\\chromedriver.exe")
def test_next_article():
try:
driver.get("http://118.25.96.118:90")
assert 'English Pal -' in driver.page_source
# login
elem = driver.find_element_by_link_text('登录')
elem.click()
uname = 'abcdefg'
password = 'abcdefg'
elem = driver.find_element_by_id('username')
elem.send_keys(uname)
elem = driver.find_element_by_id('password')
elem.send_keys(password)
elem = driver.find_element_by_xpath('/html/body/div/button') # 找到登录按钮
elem.click()
time.sleep(0.5)
assert 'EnglishPal Study Room for ' + uname in driver.title
for i in range(50):
time.sleep(0.1)
# 找到固定按钮
elem = driver.find_element_by_xpath('//*[@id="load_next_article"]')
elem.click()
except Exception as e:
print(e)
def test_local_next_article():
try:
driver.get("http://127.0.0.1:5000")
assert 'English Pal -' in driver.page_source
# login
elem = driver.find_element_by_link_text('注册')
elem.click()
uname = 'abcdefg'
password = 'abcdefg'
elem = driver.find_element_by_id('username')
elem.send_keys(uname)
elem = driver.find_element_by_id('password')
elem.send_keys(password)
elem = driver.find_element_by_id('password2')
elem.send_keys(password)
time.sleep(0.5)
elem = driver.find_element_by_class_name('btn') # 找到提交按钮
elem.click()
time.sleep(0.5)
try:
WebDriverWait(driver, 1).until(EC.alert_is_present())
driver.switch_to.alert.accept()
except (UnexpectedAlertPresentException, NoAlertPresentException):
pass
time.sleep(0.5)
assert 'EnglishPal Study Room for ' + uname in driver.title
for i in range(50):
time.sleep(0.1)
# 找到固定按钮
elem = driver.find_element_by_xpath('//*[@id="load_next_article"]')
elem.click()
except Exception as e:
print(e)