Compare commits
27 Commits
70fc469f5e
...
92a1af4222
Author | SHA1 | Date |
---|---|---|
Lan Hui | 92a1af4222 | |
mrlan | 79dff9a3b5 | |
Lan Hui | bd4fb6846b | |
Lan Hui | 2e203699c0 | |
mrlan | d502b3f474 | |
Lan Hui | 66899376c3 | |
mrlan | 6cc7f043da | |
Lan Hui | 1d80fa8886 | |
mrlan | dc3ef2bc9f | |
Lan Hui | 9eac40493b | |
Lan Hui | fe6a28a81d | |
mrlan | bf8bb1a6bc | |
mrlan | 7a97e25b8c | |
陈宇航 | 9bbd3a978d | |
夏栢芝 | 6b3efad1dc | |
Kikky666 | 02f3c4fdfa | |
钟埸 | 18472acd3d | |
钟埸 | 75c96a60df | |
张旭东 | 5657d8d5ee | |
张旭东 | 1f718e201f | |
宋海燕 | 7cf9c7cf56 | |
Yzccc | 6633df7b70 | |
Yzccc | ccf22af9df | |
姜潮 | 3383e411ec | |
姜潮 | f4488672ec | |
姜潮 | 54d09469f5 | |
姜潮 | 4b06915dc4 |
|
@ -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 model.article import get_all_articles, get_article_by_id, get_number_of_articles
|
||||
import logging
|
||||
|
||||
import re
|
||||
path_prefix = './'
|
||||
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():
|
||||
return get_number_of_articles()
|
||||
|
@ -86,6 +108,9 @@ def get_today_article(user_word_list, visited_articles):
|
|||
|
||||
today_article = None
|
||||
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 = {
|
||||
"user_level": '%4.1f' % user_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']),
|
||||
"source": d["source"],
|
||||
"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
|
||||
|
|
|
@ -79,18 +79,18 @@ def article():
|
|||
"username": session.get("username"),
|
||||
}
|
||||
|
||||
|
||||
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":
|
||||
if request.method == "POST":
|
||||
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", "")
|
||||
source = data.get("source", "")
|
||||
question = data.get("question", "")
|
||||
|
@ -99,9 +99,9 @@ def article():
|
|||
if level not in ['1', '2', '3', '4']:
|
||||
return "Level must be between 1 and 4."
|
||||
add_article(content, source, level, question)
|
||||
_update_context()
|
||||
title = content.split('\n')[0]
|
||||
flash(f'Article added. Title: {title}')
|
||||
_update_context() # 这行应在flash之后 否则会发生新建的文章即点即删
|
||||
|
||||
return render_template("admin_manage_article.html", **context)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
16
app/main.py
16
app/main.py
|
@ -79,6 +79,19 @@ def mainpage():
|
|||
根据GET或POST方法来返回不同的主界面
|
||||
: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
|
||||
content = escape(request.form['content'])
|
||||
f = WordFreq(content)
|
||||
|
@ -102,7 +115,8 @@ def mainpage():
|
|||
d_len=d_len,
|
||||
lst=lst,
|
||||
yml=Yaml.yml,
|
||||
number_of_essays=number_of_essays)
|
||||
number_of_essays=number_of_essays,
|
||||
ratio = ratio)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -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);
|
|
@ -7,6 +7,11 @@
|
|||
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" />
|
||||
<link href="../static/css/bootstrap.css" rel="stylesheet">
|
||||
<script>
|
||||
function confirmDeletion(articleId, articleTitle) {
|
||||
return confirm(`确认删除文章 "${articleTitle}" (ID: ${articleId}) 吗?`);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body class="container" style="width: 800px; margin: auto; margin-top:24px;">
|
||||
|
@ -66,9 +71,10 @@
|
|||
<div class="list-group">
|
||||
{% for text in text_list %}
|
||||
<div class="list-group-item list-group-item-action" aria-current="true">
|
||||
<div>
|
||||
<a type="button" href="/admin/article?delete_id={{text.article_id}}" class="btn btn-outline-danger btn-sm">删除</a>
|
||||
</div>
|
||||
<form action="/admin/article" method="post" style="display: inline;">
|
||||
<input type="hidden" name="delete_id" value="{{ text.article_id }}">
|
||||
<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">
|
||||
<h5 class="mb-1">{{ text.title }}</h5>
|
||||
</div>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<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>
|
||||
{% 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>
|
||||
<form method="post" action="/">
|
||||
<textarea name="content" id="article" rows="10" cols="120"></textarea><br/>
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
{% block body %}
|
||||
{% if session['logged_in'] %}
|
||||
|
||||
You're logged in already! <a href="/logout">Logout</a>.
|
||||
|
||||
{% else %}
|
||||
<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">
|
||||
<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>
|
||||
var slider
|
||||
let username,password,password2
|
||||
$(document).ready(function() {
|
||||
slider = new SliderUnlock("#slider", {
|
||||
successLabelTip: "验证成功"
|
||||
}, function() {
|
||||
|
||||
});
|
||||
slider.init(); // 初始化滑块解锁功能
|
||||
});
|
||||
|
||||
function signup(){
|
||||
let username = $("#username").val();
|
||||
let password = $("#password").val();
|
||||
let password2 = $("#password2").val();
|
||||
// 发起 AJAX 请求来处理注册
|
||||
username = $("#username").val().trim();
|
||||
password = $("#password").val().trim();
|
||||
password2 = $("#password2").val().trim();
|
||||
|
||||
// 基本表单验证
|
||||
if (username === "" || password === "" || password2 === "") {
|
||||
alert('输入不能为空!');
|
||||
return false;
|
||||
|
@ -28,8 +44,15 @@ You're logged in already! <a href="/logout">Logout</a>.
|
|||
alert('密码过于简单。(密码长度至少4位)');
|
||||
return false;
|
||||
}
|
||||
$.post("/signup", {'username': username, 'password': password},
|
||||
function (response) {
|
||||
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";
|
||||
|
@ -37,7 +60,7 @@ You're logged in already! <a href="/logout">Logout</a>.
|
|||
alert('用户名密码验证失败。');
|
||||
window.location.href = "/signup";
|
||||
} else if (response.status === '2') {
|
||||
let f = confirm("恭喜,你已成功注册,你的用户名是"+username+'.\n点击“确认”开始使用,或点击“取消”返回首页');
|
||||
var f = confirm("恭喜,你已成功注册,你的用户名是" + username + '.\n点击“确认”开始使用,或点击“取消”返回首页');
|
||||
if (f) {
|
||||
window.location.href = '/' + username + '/userpage';
|
||||
} else {
|
||||
|
@ -46,27 +69,39 @@ You're logged in already! <a href="/logout">Logout</a>.
|
|||
} 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>
|
||||
|
||||
<p><input type="username" id="username" placeholder="输入用户名" class="username"></p>
|
||||
<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>
|
||||
<button type="button" class="btn" onclick="signup()">注册</button>
|
||||
|
||||
<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>
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
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"/>
|
||||
<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>
|
||||
|
||||
{{ yml['header'] | safe }}
|
||||
|
@ -71,14 +73,19 @@
|
|||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<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()" style="display: none" title="上一篇 Previous Article">⇦</button>
|
||||
<div class="pagination">
|
||||
<button class="arrow" id="load_pre_article" onclick="load_pre_article();Reader.stopRead()" title="Previous Article">
|
||||
<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>
|
||||
<div id="text-content">
|
||||
<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/>
|
||||
<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/>
|
||||
|
@ -166,7 +173,6 @@
|
|||
<input id="selected-words2" type="hidden" value="{{ words }}">
|
||||
{% endif %}
|
||||
</div>
|
||||
<label id="selected-words3" type="hidden"></label>
|
||||
{{ yml['footer'] | safe }}
|
||||
{% if yml['js']['bottom'] %}
|
||||
{% for js in yml['js']['bottom'] %}
|
||||
|
@ -198,11 +204,12 @@
|
|||
elements.chooseCheckbox.checked = settings.chooseChecked;
|
||||
elements.rangeComponent.value = settings.rangeValue;
|
||||
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');
|
||||
}
|
||||
|
||||
// 事件监听器
|
||||
|
@ -230,6 +237,9 @@
|
|||
success: function(data) {
|
||||
// 更新页面内容
|
||||
if(data['today_article']){
|
||||
// answer不可见
|
||||
const e = document.getElementById('answer');
|
||||
e.style.display = 'none';
|
||||
update(data['today_article']);
|
||||
check_pre(data['visited_articles']);
|
||||
check_next(data['result_of_generate_article']);
|
||||
|
@ -244,6 +254,9 @@
|
|||
success: function(data) {
|
||||
// 更新页面内容
|
||||
if(data['today_article']){
|
||||
// answer不可见
|
||||
const e = document.getElementById('answer');
|
||||
e.style.display = 'none';
|
||||
update(data['today_article']);
|
||||
check_pre(data['visited_articles']);
|
||||
}
|
||||
|
@ -259,18 +272,18 @@
|
|||
$('#source').html(today_article['source']);
|
||||
$('#question').html(today_article["question"]);
|
||||
$('#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
|
||||
setTimeout(() => {document.querySelector('#text_level').classList.remove('mark');}, 2000);
|
||||
document.querySelector('#user_level').classList.add('mark'); // do the same thing for user difficulty level
|
||||
setTimeout(() => {document.querySelector('#user_level').classList.remove('mark');}, 2000);
|
||||
}
|
||||
<!-- 检查是否存在上一篇或下一篇,不存在则对应按钮隐藏-->
|
||||
function check_pre(visited_articles){
|
||||
if((visited_articles=='')||(visited_articles['index']<=0)){
|
||||
$('#load_pre_article').hide();
|
||||
$('#load_pre_article').addClass('gray-background'); // 设置为灰色
|
||||
sessionStorage.setItem('pre_page_button', 'display')
|
||||
}else{
|
||||
$('#load_pre_article').show();
|
||||
$('#load_pre_article').removeClass('gray-background'); // 设置为正常蓝色
|
||||
sessionStorage.setItem('pre_page_button', 'show')
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue