Compare commits
No commits in common. "c453317ad88e2cc5f3a174c4160465fad123eed4" and "109a9447a7d5fa24920ac7764994c10e03731ef4" have entirely different histories.
c453317ad8
...
109a9447a7
|
@ -9,32 +9,10 @@ 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()
|
||||||
|
@ -108,9 +86,6 @@ 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,
|
||||||
|
@ -119,8 +94,7 @@ 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
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from flask import *
|
from flask import *
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
|
from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
|
||||||
|
from model import deactivate_user
|
||||||
|
|
||||||
# 初始化蓝图
|
# 初始化蓝图
|
||||||
accountService = Blueprint("accountService", __name__)
|
accountService = Blueprint("accountService", __name__)
|
||||||
|
@ -58,12 +59,6 @@ def login():
|
||||||
username = escape(request.form['username'])
|
username = escape(request.form['username'])
|
||||||
password = escape(request.form['password'])
|
password = escape(request.form['password'])
|
||||||
verified = verify_user(username, password)
|
verified = verify_user(username, password)
|
||||||
#读black.txt文件判断用户是否在黑名单中
|
|
||||||
with open('black.txt') as f:
|
|
||||||
for line in f:
|
|
||||||
line = line.strip()
|
|
||||||
if username == line:
|
|
||||||
return jsonify({'status': '5'})
|
|
||||||
with open('black.txt', 'a+') as f:
|
with open('black.txt', 'a+') as f:
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
@ -71,7 +66,7 @@ def login():
|
||||||
for i in lines:
|
for i in lines:
|
||||||
line.append(i.strip('\n'))
|
line.append(i.strip('\n'))
|
||||||
#读black.txt文件判断用户是否在黑名单中
|
#读black.txt文件判断用户是否在黑名单中
|
||||||
if verified and username not in line: #TODO: 一个用户名是另外一个用户名的子串怎么办?
|
if verified and username not in line:
|
||||||
# 登录成功,写入session
|
# 登录成功,写入session
|
||||||
session['logged_in'] = True
|
session['logged_in'] = True
|
||||||
session[username] = username
|
session[username] = username
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
28
app/main.py
28
app/main.py
|
@ -2,7 +2,7 @@
|
||||||
# Copyright 2019 (C) Hui Lan <hui.lan@cantab.net>
|
# Copyright 2019 (C) Hui Lan <hui.lan@cantab.net>
|
||||||
# Written permission must be obtained from the author for commercial uses.
|
# Written permission must be obtained from the author for commercial uses.
|
||||||
###########################################################################
|
###########################################################################
|
||||||
from flask import abort, jsonify
|
from flask import abort
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from Login import *
|
from Login import *
|
||||||
from Article import *
|
from Article import *
|
||||||
|
@ -11,7 +11,6 @@ from user_service import userService
|
||||||
from account_service import accountService
|
from account_service import accountService
|
||||||
from admin_service import adminService, ADMIN_NAME
|
from admin_service import adminService, ADMIN_NAME
|
||||||
import os
|
import os
|
||||||
from translate import *
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = os.urandom(32)
|
app.secret_key = os.urandom(32)
|
||||||
|
@ -80,19 +79,6 @@ 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)
|
||||||
|
@ -116,17 +102,7 @@ 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)
|
|
||||||
|
|
||||||
@app.route("/translate", methods=['POST'])
|
|
||||||
def translate_word():
|
|
||||||
data = request.get_json()
|
|
||||||
word = data.get('word', '')
|
|
||||||
from_lang = data.get('from_lang', 'en') # 假设默认源语言是英语
|
|
||||||
to_lang = data.get('to_lang', 'zh') # 假设默认目标语言是中文
|
|
||||||
result = translate(word, from_lang, to_lang)
|
|
||||||
return jsonify({'translation': result})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
/* 按钮(上一篇,下一篇)样式 */
|
|
||||||
.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;
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
|
@ -17,20 +17,21 @@ function showBtnHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWord() {
|
function getWord() {
|
||||||
return window.getSelection ? window.getSelection().toString() : document.selection.createRange().text;
|
return window.getSelection ? window.getSelection() : document.selection.createRange().text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function highLight() {
|
function highLight() {
|
||||||
if (!isHighlight) return;
|
if (!isHighlight) return;
|
||||||
let word = (getWord() + "").trim().replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
|
let word = (getWord() + "").trim();
|
||||||
let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器
|
let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器
|
||||||
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 = dictionaryWords === null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value;
|
let allWords = dictionaryWords === null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value;
|
||||||
let highlightWords = document.getElementById("selected-words3");
|
highlightWords = document.getElementById("selected-words3");
|
||||||
allWords = highlightWords == null ? allWords : allWords + " " + highlightWords.value;
|
allWords = highlightWords == null ? allWords : allWords + " " + highlightWords.value;
|
||||||
const list = allWords.split(" "); // 将所有的生词放入一个list中
|
const list = allWords.split(" "); // 将所有的生词放入一个list中
|
||||||
if(word !== null && word !== "" && word !== " "){
|
if(word !== null && word !== "" && word !== " "){
|
||||||
|
let articleContent_fb2 = articleContent;
|
||||||
if(localStorage.getItem("nowWords").indexOf(word) !== -1 || localStorage.getItem("nowWords").indexOf(word.toLowerCase()) !== -1){
|
if(localStorage.getItem("nowWords").indexOf(word) !== -1 || localStorage.getItem("nowWords").indexOf(word.toLowerCase()) !== -1){
|
||||||
articleContent = articleContent.replace(new RegExp('<span class="highlighted">' + word + '</span>', "gi"), word);
|
articleContent = articleContent.replace(new RegExp('<span class="highlighted">' + word + '</span>', "gi"), word);
|
||||||
pickedWords.value = localStorage.getItem("nowWords").replace(word,"");
|
pickedWords.value = localStorage.getItem("nowWords").replace(word,"");
|
||||||
|
@ -57,7 +58,6 @@ function highLight() {
|
||||||
articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "<span class='highlighted'>" + word + "</span>");
|
articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "<span class='highlighted'>" + word + "</span>");
|
||||||
}
|
}
|
||||||
document.getElementById("article").innerHTML = articleContent;
|
document.getElementById("article").innerHTML = articleContent;
|
||||||
addClickEventToHighlightedWords();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelHighlighting() {
|
function cancelHighlighting() {
|
||||||
|
@ -83,62 +83,7 @@ function toggleHighlighting() {
|
||||||
isHighlight = true;
|
isHighlight = true;
|
||||||
highLight();
|
highLight();
|
||||||
}
|
}
|
||||||
localStorage.setItem('highlightChecked', isHighlight);
|
localStorage.setItem('highlightChecked', isHighlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showWordMeaning(event) {
|
showBtnHandler();
|
||||||
const word = event.target.innerText.trim().replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "").toLowerCase();
|
|
||||||
const apiUrl = '/translate';
|
|
||||||
const rect = event.target.getBoundingClientRect();
|
|
||||||
const tooltipX = rect.left + window.scrollX;
|
|
||||||
const tooltipY = rect.top + window.scrollY + rect.height;
|
|
||||||
// 发送POST请求
|
|
||||||
fetch(apiUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ word: word }), // 发送的JSON数据
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not ok');
|
|
||||||
}
|
|
||||||
return response.json(); // 解析JSON响应
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
// 假设data.translation是翻译结果
|
|
||||||
const tooltip = document.getElementById('tooltip');
|
|
||||||
if (!tooltip) {
|
|
||||||
console.error('Tooltip element not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tooltip.textContent = data.translation || '没有找到该单词的中文意思';
|
|
||||||
tooltip.style.left = `${tooltipX}px`;
|
|
||||||
tooltip.style.top = `${tooltipY}px`;
|
|
||||||
tooltip.style.display = 'block';
|
|
||||||
tooltip.style.position = 'absolute';
|
|
||||||
tooltip.style.background = 'yellow';
|
|
||||||
|
|
||||||
// 可以在这里添加点击事件监听器来隐藏tooltip,但注意避免内存泄漏
|
|
||||||
document.addEventListener('click', function handler(e) {
|
|
||||||
if (!tooltip.contains(e.target)) {
|
|
||||||
tooltip.style.display = 'none';
|
|
||||||
document.removeEventListener('click', handler);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('There was a problem with your fetch operation:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function addClickEventToHighlightedWords() {
|
|
||||||
const highlightedWords = document.querySelectorAll('.highlighted');
|
|
||||||
highlightedWords.forEach(word => {
|
|
||||||
word.addEventListener('click', showWordMeaning);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
showBtnHandler();
|
|
File diff suppressed because one or more lines are too long
|
@ -1,200 +0,0 @@
|
||||||
/**
|
|
||||||
* 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);
|
|
|
@ -68,7 +68,6 @@ function read_word(theWord) {
|
||||||
Reader.read(to_speak, inputSlider.value);
|
Reader.read(to_speak, inputSlider.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* interface Word {
|
* interface Word {
|
||||||
* word: string,
|
* word: string,
|
||||||
|
@ -103,12 +102,9 @@ 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>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除某一词频元素
|
* 删除某一词频元素
|
||||||
* 此处word为词频元素对应的单词
|
* 此处word为词频元素对应的单词
|
||||||
|
@ -175,60 +171,4 @@ function compareWord(first, second) {
|
||||||
return first.word < second.word ? -1 : 1;
|
return first.word < second.word ? -1 : 1;
|
||||||
}
|
}
|
||||||
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 个单词学习
|
|
||||||
*/
|
|
||||||
function random_select_word(word) {
|
|
||||||
|
|
||||||
// 获取所有带有 "word-container" 类的 <p> 标签
|
|
||||||
const container = document.querySelector('.word-container');
|
|
||||||
|
|
||||||
console.log("container",container)
|
|
||||||
|
|
||||||
// 获取所有带有"new-word"类的<p>标签
|
|
||||||
let wordContainers = container.querySelectorAll('.new-word');
|
|
||||||
|
|
||||||
// 检查是否存在带有"new-word"类的<p>标签
|
|
||||||
if (wordContainers.length > 0) {
|
|
||||||
// 将NodeList转换为数组
|
|
||||||
let wordContainersArray = [...wordContainers];
|
|
||||||
|
|
||||||
// 随机打乱数组,乱序
|
|
||||||
for (let i = wordContainersArray.length - 1; i > 0; i--) {
|
|
||||||
const j = Math.floor(Math.random() * (i + 1));
|
|
||||||
[wordContainersArray[i], wordContainersArray[j]] = [wordContainersArray[j], wordContainersArray[i]];
|
|
||||||
}
|
|
||||||
|
|
||||||
wordContainersArray.forEach((p, index) => {
|
|
||||||
if (index < 10) {
|
|
||||||
p.style.display = 'block';
|
|
||||||
} else {
|
|
||||||
p.style.display = 'none';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,11 +7,6 @@
|
||||||
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;">
|
||||||
|
@ -71,10 +66,9 @@
|
||||||
<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">
|
||||||
<form action="/admin/article" method="post" style="display: inline;">
|
<div>
|
||||||
<input type="hidden" name="delete_id" value="{{ text.article_id }}">
|
<a type="button" href="/admin/article?delete_id={{text.article_id}}" class="btn btn-outline-danger btn-sm">删除</a>
|
||||||
<button type="submit" class="btn btn-outline-danger btn-sm" onclick="return confirmDeletion('{{ text.article_id }}', '{{ text.title }}')">删除</button>
|
</div>
|
||||||
</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>
|
||||||
|
|
|
@ -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> 篇,覆盖 <span class="badge bg-success"> {{ (ratio * 100) | int }}% </span> 的 Oxford5000 单词</div>
|
<div class="alert alert-success" role="alert">共有文章 <span class="badge bg-success"> {{ number_of_essays }} </span> 篇</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/>
|
||||||
|
|
|
@ -1,107 +1,72 @@
|
||||||
{% 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">
|
||||||
<meta charset="UTF-8">
|
<script src="static/js/jquery.js"></script>
|
||||||
<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>
|
||||||
var slider
|
function signup() {
|
||||||
let username,password,password2
|
let username = $("#username").val();
|
||||||
$(document).ready(function() {
|
let password = $("#password").val();
|
||||||
slider = new SliderUnlock("#slider", {
|
let password2 = $("#password2").val();
|
||||||
successLabelTip: "验证成功"
|
if (username === "" || password === "" || password2 === ""){
|
||||||
}, function() {
|
alert('输入不能为空!');
|
||||||
|
return false;
|
||||||
});
|
|
||||||
slider.init(); // 初始化滑块解锁功能
|
|
||||||
});
|
|
||||||
|
|
||||||
function signup(){
|
|
||||||
// 发起 AJAX 请求来处理注册
|
|
||||||
username = $("#username").val().trim();
|
|
||||||
password = $("#password").val().trim();
|
|
||||||
password2 = $("#password2").val().trim();
|
|
||||||
|
|
||||||
// 基本表单验证
|
|
||||||
if (username === "" || password === "" || password2 === "") {
|
|
||||||
alert('输入不能为空!');
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
if (password.includes(' ') || password2.includes(' ')) {
|
||||||
return false;
|
alert('输入不能包含空格!');
|
||||||
}
|
return false;
|
||||||
</script>
|
}
|
||||||
<p>{{ get_flashed_messages()[0] | safe }}</p>
|
if (password !== password2) {
|
||||||
|
alert('确认密码与输入密码不一致!');
|
||||||
<div class="container">
|
return false;
|
||||||
<section class="signin-heading">
|
}
|
||||||
<h1>Sign up</h1>
|
if (password.length < 4) {
|
||||||
</section>
|
alert('密码过于简单。(密码长度至少4位)');
|
||||||
|
return false;
|
||||||
<form>
|
}
|
||||||
<p><input type="text" id="username" placeholder="输入用户名" class="username"></p>
|
$.post("/signup", {'username': username, 'password': password},
|
||||||
<p><input type="password" id="password" placeholder="输入密码" class="password"></p>
|
function (response) {
|
||||||
<p><input type="password" id="password2" placeholder="确认密码" class="password"></p>
|
if (response.status === '0') {
|
||||||
|
alert('用户名'+username+'已经被注册。');
|
||||||
<div id="slider">
|
window.location.href = "/signup";
|
||||||
<div id="slider_bg"></div>
|
} else if (response.status === '1') {
|
||||||
<span id="label">>></span> <span id="labelTip">-----滑动验证你是不是人类</span>
|
alert('用户名密码验证失败。');
|
||||||
</div>
|
window.location.href = "/signup";
|
||||||
|
} else if (response.status === '2') {
|
||||||
<button type="button" class="btn" onclick="signup()">注册</button>
|
let f = confirm("恭喜,你已成功注册,你的用户名是"+username+'.\n点击“确认”开始使用,或点击“取消”返回首页');
|
||||||
</form>
|
if (f) {
|
||||||
</div>
|
window.location.href = '/'+username+'/userpage';
|
||||||
|
} else {
|
||||||
<script>
|
window.location.href = '/';
|
||||||
// Bind click event to the signup button
|
}
|
||||||
$(".btn").click(function() {
|
} else if (response.status === '3') {
|
||||||
// Trigger slider unlock
|
alert(response.warn);
|
||||||
var slider = new SliderUnlock("#slider");
|
}
|
||||||
slider.isOk();
|
}
|
||||||
});
|
)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
</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 %}
|
||||||
|
|
||||||
|
|
|
@ -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,8 +6,6 @@
|
||||||
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 }}
|
||||||
|
@ -73,20 +71,15 @@
|
||||||
<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_pre_article" onclick="load_pre_article();Reader.stopRead()" title="Previous Article">
|
<button class="arrow" id="load_next_article" onclick="load_next_article();Reader.stopRead()" title="下一篇 Next Article">⇨</button>
|
||||||
<i class="fas fa-chevron-left"></i> 上一篇
|
<button class="arrow" id="load_pre_article" onclick="load_pre_article();Reader.stopRead()" style="display: none" title="上一篇 Previous Article">⇦</button>
|
||||||
</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. The Oxford word coverage is <span class="text-decoration-underline" id="ratio">{{ (today_article["ratio"] * 100) | int }}%.</span></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.</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/>
|
||||||
|
@ -107,7 +100,6 @@
|
||||||
<button onclick="toggle_visibility('answer');">ANSWER</button>
|
<button onclick="toggle_visibility('answer');">ANSWER</button>
|
||||||
<div id="answer" style="display:none;">{{ today_article['answer'] }}</div><br/>
|
<div id="answer" style="display:none;">{{ today_article['answer'] }}</div><br/>
|
||||||
</div>
|
</div>
|
||||||
<div id="tooltip"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-success" role="alert" id="not_found" style="display:none;">
|
<div class="alert alert-success" role="alert" id="not_found" style="display:none;">
|
||||||
<p class="text-muted"><span class="badge bg-success">Notes:</span><br>No article is currently available for you. You can try again a few times or mark new words in the passage to improve your level.</p>
|
<p class="text-muted"><span class="badge bg-success">Notes:</span><br>No article is currently available for you. You can try again a few times or mark new words in the passage to improve your level.</p>
|
||||||
|
@ -147,18 +139,12 @@
|
||||||
|
|
||||||
{% if d_len > 0 %}
|
{% if d_len > 0 %}
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<b>我的生词簿</b>
|
<b>我的生词簿</b>
|
||||||
<label for="move_dynamiclly">
|
<label for="move_dynamiclly">
|
||||||
<input type="checkbox" name="move_dynamiclly" id="move_dynamiclly" checked>
|
<input type="checkbox" name="move_dynamiclly" id="move_dynamiclly" checked>
|
||||||
允许动态调整顺序
|
允许动态调整顺序
|
||||||
</label>
|
</label>
|
||||||
<br>
|
|
||||||
<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>
|
|
||||||
</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 %}
|
||||||
|
@ -174,13 +160,10 @@
|
||||||
<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>
|
||||||
{{ yml['footer'] | safe }}
|
{{ yml['footer'] | safe }}
|
||||||
|
@ -189,28 +172,6 @@
|
||||||
<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 = {
|
||||||
|
@ -236,12 +197,11 @@
|
||||||
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')) {
|
||||||
if (sessionStorage.getItem('pre_page_button') === 'display' || !sessionStorage.getItem('pre_page_button')) {
|
$('#load_pre_article').show();
|
||||||
$('#load_pre_article').addClass('gray-background');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 事件监听器
|
// 事件监听器
|
||||||
|
@ -269,9 +229,6 @@
|
||||||
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']);
|
||||||
|
@ -286,9 +243,6 @@
|
||||||
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']);
|
||||||
}
|
}
|
||||||
|
@ -304,18 +258,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').addClass('gray-background'); // 设置为灰色
|
$('#load_pre_article').hide();
|
||||||
sessionStorage.setItem('pre_page_button', 'display')
|
sessionStorage.setItem('pre_page_button', 'display')
|
||||||
}else{
|
}else{
|
||||||
$('#load_pre_article').removeClass('gray-background'); // 设置为正常蓝色
|
$('#load_pre_article').show();
|
||||||
sessionStorage.setItem('pre_page_button', 'show')
|
sessionStorage.setItem('pre_page_button', 'show')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,5 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<script>window.history.replaceState(null, null, window.location.href);
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
import requests
|
|
||||||
import hashlib
|
|
||||||
import time
|
|
||||||
from urllib.parse import urlencode
|
|
||||||
|
|
||||||
# 假设这是从某个配置文件中读取的
|
|
||||||
class BaiduContent:
|
|
||||||
APPID = '20240702002090356'
|
|
||||||
SECRET = '3CcqcMAJdIIpgG0uMS_f'
|
|
||||||
|
|
||||||
def generate_sign(q, salt):
|
|
||||||
"""生成百度翻译API所需的签名"""
|
|
||||||
appid = BaiduContent.APPID
|
|
||||||
secret = BaiduContent.SECRET
|
|
||||||
appid_with_data = appid + q + salt + secret
|
|
||||||
md5_obj = hashlib.md5(appid_with_data.encode('utf-8'))
|
|
||||||
return md5_obj.hexdigest()
|
|
||||||
|
|
||||||
def translate(q, from_lang, to_lang):
|
|
||||||
"""调用百度翻译API进行翻译"""
|
|
||||||
salt = str(int(time.time())) # 生成一个时间戳作为salt
|
|
||||||
sign = generate_sign(q, salt)
|
|
||||||
|
|
||||||
# 封装请求参数
|
|
||||||
params = {
|
|
||||||
'q': q,
|
|
||||||
'from': from_lang,
|
|
||||||
'to': to_lang,
|
|
||||||
'appid': BaiduContent.APPID,
|
|
||||||
'salt': salt,
|
|
||||||
'sign': sign
|
|
||||||
}
|
|
||||||
|
|
||||||
# 构造请求URL(百度翻译API使用POST请求,并将参数放在请求体中)
|
|
||||||
url = "http://api.fanyi.baidu.com/api/trans/vip/translate"
|
|
||||||
|
|
||||||
# 发送POST请求
|
|
||||||
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
||||||
data = urlencode(params).encode('utf-8') # 注意:需要编码为bytes
|
|
||||||
|
|
||||||
response = requests.post(url, data=data, headers=headers)
|
|
||||||
|
|
||||||
# 检查响应状态码
|
|
||||||
if response.status_code == 200:
|
|
||||||
# 解析并返回JSON响应体中的翻译结果
|
|
||||||
try:
|
|
||||||
return response.json()['trans_result'][0]['dst']
|
|
||||||
except (KeyError, IndexError):
|
|
||||||
return "Invalid response from API"
|
|
||||||
else:
|
|
||||||
# 返回错误信息或状态码
|
|
||||||
return {"error": f"Failed with status code {response.status_code}"}
|
|
|
@ -4,5 +4,5 @@ PyYAML~=6.0
|
||||||
pony==0.7.16
|
pony==0.7.16
|
||||||
snowballstemmer==2.2.0
|
snowballstemmer==2.2.0
|
||||||
Werkzeug==2.2.2
|
Werkzeug==2.2.2
|
||||||
requests
|
|
||||||
pytest~=8.1.1
|
pytest~=8.1.1
|
Loading…
Reference in New Issue