hexo-theme-ayeria 1.9.11 → 1.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +37 -37
- package/README.en.md +560 -560
- package/README.md +560 -560
- package/_config.yml +271 -271
- package/_scaffolds/post.md +8 -8
- package/index.js +11 -2
- package/languages/de.yml +39 -39
- package/languages/default.yml +40 -39
- package/languages/en.yml +40 -39
- package/languages/es.yml +39 -39
- package/languages/fr.yml +39 -39
- package/languages/ja.yml +39 -39
- package/languages/ko.yml +39 -39
- package/languages/nl.yml +39 -39
- package/languages/no.yml +39 -39
- package/languages/pt.yml +39 -39
- package/languages/ru.yml +39 -39
- package/languages/vi.yml +39 -39
- package/languages/zh-CN.yml +40 -39
- package/languages/zh-TW.yml +40 -39
- package/layout/_partial/ads.ejs +8 -8
- package/layout/_partial/after-footer.ejs +84 -84
- package/layout/_partial/archive-post.ejs +13 -13
- package/layout/_partial/archive.ejs +61 -61
- package/layout/_partial/article.ejs +94 -94
- package/layout/_partial/ayeria.ejs +53 -53
- package/layout/_partial/baidu-analytics.ejs +11 -11
- package/layout/_partial/broadcast.ejs +19 -19
- package/layout/_partial/float-btns.ejs +7 -7
- package/layout/_partial/footer.ejs +61 -61
- package/layout/_partial/google-analytics.ejs +10 -10
- package/layout/_partial/head.ejs +64 -68
- package/layout/_partial/katex.ejs +21 -21
- package/layout/_partial/lock.ejs +37 -37
- package/layout/_partial/mathjax.ejs +18 -18
- package/layout/_partial/modal.ejs +70 -76
- package/layout/_partial/music.ejs +15 -15
- package/layout/_partial/post/albums.ejs +16 -16
- package/layout/_partial/post/author.ejs +7 -7
- package/layout/_partial/post/busuanzi.ejs +4 -4
- package/layout/_partial/post/category.ejs +9 -9
- package/layout/_partial/post/clipboard.ejs +54 -54
- package/layout/_partial/post/date.ejs +2 -2
- package/layout/_partial/post/gallery.ejs +15 -15
- package/layout/_partial/post/giscus.ejs +40 -40
- package/layout/_partial/post/gitalk.ejs +12 -12
- package/layout/_partial/post/justifiedGallery.ejs +8 -8
- package/layout/_partial/post/nav.ejs +22 -22
- package/layout/_partial/post/search.ejs +3 -3
- package/layout/_partial/post/share.ejs +53 -53
- package/layout/_partial/post/tag.ejs +5 -5
- package/layout/_partial/post/title.ejs +16 -16
- package/layout/_partial/post/tocbot.ejs +6 -6
- package/layout/_partial/post/topping.ejs +2 -2
- package/layout/_partial/post/twikoo.ejs +7 -7
- package/layout/_partial/post/valine.ejs +48 -48
- package/layout/_partial/post/word.ejs +19 -19
- package/layout/_partial/sidebar.ejs +48 -48
- package/layout/_partial/viewer.ejs +105 -105
- package/layout/categories.ejs +8 -8
- package/layout/friends.ejs +19 -19
- package/layout/index.ejs +4 -4
- package/layout/layout.ejs +35 -30
- package/layout/page.ejs +2 -2
- package/layout/plain-page.ejs +4 -4
- package/layout/post.ejs +2 -2
- package/layout/tags.ejs +88 -88
- package/package.json +39 -39
- package/scripts/default_config.js +6 -6
- package/scripts/events/index.js +11 -11
- package/scripts/events/lib/hello.js +38 -38
- package/scripts/events/lib/merge-configs.js +28 -28
- package/scripts/filters/index.js +13 -13
- package/scripts/filters/meta_generator.js +17 -17
- package/scripts/helpers/ayeria-plus-vendors.js +9 -9
- package/scripts/helpers/category-tree.js +90 -90
- package/scripts/helpers/wordcount.js +39 -39
- package/scripts/lib/core.js +25 -25
- package/scripts/utils/join-path.js +12 -12
- package/scripts/utils/object.js +31 -31
- package/source/404.html +187 -187
- package/source/css/ayeria-layout.styl +48 -48
- package/source/css/clipboard.styl +37 -37
- package/source/css/custom.styl +17 -17
- package/source/css/fonts/remixicon.css +1816 -1816
- package/source/css/fonts/remixicon.svg +5329 -5329
- package/source/data/random-sentences.txt +2629 -141
- package/source/dist/main.css +1 -1
- package/source/dist/main.js +1 -1
- package/source/js/clickBoom1.js +152 -152
- package/source/js/clickBoom2.js +180 -180
- package/source/js/jquery-3.6.0.min.js +2 -2
- package/source/js/lazyload.min.js +7 -7
- package/source/js/search.js +126 -126
- package/source/js/random-sentences.js +0 -166
package/source/js/search.js
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
// A local search script with the help of [hexo-generator-search](https://github.com/PaicHyperionDev/hexo-generator-search)
|
|
2
|
-
// Copyright (C) 2015
|
|
3
|
-
// Joseph Pan <http://github.com/wzpan>
|
|
4
|
-
// Shuhao Mao <http://github.com/maoshuhao>
|
|
5
|
-
// This library is free software; you can redistribute it and/or modify
|
|
6
|
-
// it under the terms of the GNU Lesser General Public License as
|
|
7
|
-
// published by the Free Software Foundation; either version 2.1 of the
|
|
8
|
-
// License, or (at your option) any later version.
|
|
9
|
-
//
|
|
10
|
-
// This library is distributed in the hope that it will be useful, but
|
|
11
|
-
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
// Lesser General Public License for more details.
|
|
14
|
-
//
|
|
15
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
// License along with this library; if not, write to the Free Software
|
|
17
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
18
|
-
// 02110-1301 USA
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
var searchFunc = function (path, search_id, content_id) {
|
|
22
|
-
'use strict';
|
|
23
|
-
var BTN = "<button type='button' class='local-search-close' id='local-search-close'></button>";
|
|
24
|
-
$.ajax({
|
|
25
|
-
url: path,
|
|
26
|
-
dataType: "xml",
|
|
27
|
-
success: function (xmlResponse) {
|
|
28
|
-
// get the contents from search data
|
|
29
|
-
var datas = $("entry", xmlResponse).map(function () {
|
|
30
|
-
return {
|
|
31
|
-
title: $("title", this).text(),
|
|
32
|
-
content: $("content", this).text(),
|
|
33
|
-
url: $("url", this).text()
|
|
34
|
-
};
|
|
35
|
-
}).get();
|
|
36
|
-
|
|
37
|
-
var $input = document.getElementById(search_id);
|
|
38
|
-
var $resultContent = document.getElementById(content_id);
|
|
39
|
-
|
|
40
|
-
$input.addEventListener('input', function () {
|
|
41
|
-
var str = '<ul class="search-result-list">';
|
|
42
|
-
var keywords = this.value.trim().toLowerCase().split(/[\s]+/);
|
|
43
|
-
$resultContent.innerHTML = "";
|
|
44
|
-
if (this.value.trim().length <= 0) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
// perform local searching
|
|
48
|
-
datas.forEach(function (data) {
|
|
49
|
-
var isMatch = true;
|
|
50
|
-
// var content_index = [];
|
|
51
|
-
if (!data.title || data.title.trim() === '') {
|
|
52
|
-
data.title = "Untitled";
|
|
53
|
-
}
|
|
54
|
-
var data_title = data.title.trim().toLowerCase();
|
|
55
|
-
var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
|
|
56
|
-
var data_url = data.url;
|
|
57
|
-
var index_title = -1;
|
|
58
|
-
var index_content = -1;
|
|
59
|
-
var first_occur = -1;
|
|
60
|
-
// only match artiles with not empty contents
|
|
61
|
-
if (data_content !== '') {
|
|
62
|
-
keywords.forEach(function (keyword, i) {
|
|
63
|
-
index_title = data_title.indexOf(keyword);
|
|
64
|
-
index_content = data_content.indexOf(keyword);
|
|
65
|
-
|
|
66
|
-
if (index_title < 0 && index_content < 0) {
|
|
67
|
-
isMatch = false;
|
|
68
|
-
} else {
|
|
69
|
-
if (index_content < 0) {
|
|
70
|
-
index_content = 0;
|
|
71
|
-
}
|
|
72
|
-
if (i == 0) {
|
|
73
|
-
first_occur = index_content;
|
|
74
|
-
}
|
|
75
|
-
// content_index.push({index_content:index_content, keyword_len:keyword_len});
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
isMatch = false;
|
|
80
|
-
}
|
|
81
|
-
// show search results
|
|
82
|
-
if (isMatch) {
|
|
83
|
-
str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
|
|
84
|
-
var content = data.content.trim().replace(/<[^>]+>/g, "");
|
|
85
|
-
if (first_occur >= 0) {
|
|
86
|
-
// cut out 100 characters
|
|
87
|
-
var start = first_occur - 20;
|
|
88
|
-
var end = first_occur + 80;
|
|
89
|
-
|
|
90
|
-
if (start < 0) {
|
|
91
|
-
start = 0;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (start == 0) {
|
|
95
|
-
end = 100;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (end > content.length) {
|
|
99
|
-
end = content.length;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
var match_content = content.substr(start, end);
|
|
103
|
-
|
|
104
|
-
// highlight all keywords
|
|
105
|
-
keywords.forEach(function (keyword) {
|
|
106
|
-
var regS = new RegExp(keyword, "gi");
|
|
107
|
-
match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
str += "<p class=\"search-result\">" + match_content + "...</p>"
|
|
111
|
-
}
|
|
112
|
-
str += "</li>";
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
str += "</ul>";
|
|
116
|
-
if (str.indexOf('<li>') === -1) {
|
|
117
|
-
return $resultContent.innerHTML = BTN + "<div class=\"search-result-empty\"><p><i class=\"fe fe-tired\"></i> 没有找到内容,更换下搜索词试试吧~<p></div>";
|
|
118
|
-
}
|
|
119
|
-
$resultContent.innerHTML = BTN + str;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
$(document).on('click', '#local-search-close', function () {
|
|
124
|
-
$('#local-search-input').val('');
|
|
125
|
-
$('#local-search-result').html('');
|
|
126
|
-
});
|
|
1
|
+
// A local search script with the help of [hexo-generator-search](https://github.com/PaicHyperionDev/hexo-generator-search)
|
|
2
|
+
// Copyright (C) 2015
|
|
3
|
+
// Joseph Pan <http://github.com/wzpan>
|
|
4
|
+
// Shuhao Mao <http://github.com/maoshuhao>
|
|
5
|
+
// This library is free software; you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU Lesser General Public License as
|
|
7
|
+
// published by the Free Software Foundation; either version 2.1 of the
|
|
8
|
+
// License, or (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This library is distributed in the hope that it will be useful, but
|
|
11
|
+
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
// Lesser General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU Lesser General Public
|
|
16
|
+
// License along with this library; if not, write to the Free Software
|
|
17
|
+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
18
|
+
// 02110-1301 USA
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
var searchFunc = function (path, search_id, content_id) {
|
|
22
|
+
'use strict';
|
|
23
|
+
var BTN = "<button type='button' class='local-search-close' id='local-search-close'></button>";
|
|
24
|
+
$.ajax({
|
|
25
|
+
url: path,
|
|
26
|
+
dataType: "xml",
|
|
27
|
+
success: function (xmlResponse) {
|
|
28
|
+
// get the contents from search data
|
|
29
|
+
var datas = $("entry", xmlResponse).map(function () {
|
|
30
|
+
return {
|
|
31
|
+
title: $("title", this).text(),
|
|
32
|
+
content: $("content", this).text(),
|
|
33
|
+
url: $("url", this).text()
|
|
34
|
+
};
|
|
35
|
+
}).get();
|
|
36
|
+
|
|
37
|
+
var $input = document.getElementById(search_id);
|
|
38
|
+
var $resultContent = document.getElementById(content_id);
|
|
39
|
+
|
|
40
|
+
$input.addEventListener('input', function () {
|
|
41
|
+
var str = '<ul class="search-result-list">';
|
|
42
|
+
var keywords = this.value.trim().toLowerCase().split(/[\s]+/);
|
|
43
|
+
$resultContent.innerHTML = "";
|
|
44
|
+
if (this.value.trim().length <= 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// perform local searching
|
|
48
|
+
datas.forEach(function (data) {
|
|
49
|
+
var isMatch = true;
|
|
50
|
+
// var content_index = [];
|
|
51
|
+
if (!data.title || data.title.trim() === '') {
|
|
52
|
+
data.title = "Untitled";
|
|
53
|
+
}
|
|
54
|
+
var data_title = data.title.trim().toLowerCase();
|
|
55
|
+
var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
|
|
56
|
+
var data_url = data.url;
|
|
57
|
+
var index_title = -1;
|
|
58
|
+
var index_content = -1;
|
|
59
|
+
var first_occur = -1;
|
|
60
|
+
// only match artiles with not empty contents
|
|
61
|
+
if (data_content !== '') {
|
|
62
|
+
keywords.forEach(function (keyword, i) {
|
|
63
|
+
index_title = data_title.indexOf(keyword);
|
|
64
|
+
index_content = data_content.indexOf(keyword);
|
|
65
|
+
|
|
66
|
+
if (index_title < 0 && index_content < 0) {
|
|
67
|
+
isMatch = false;
|
|
68
|
+
} else {
|
|
69
|
+
if (index_content < 0) {
|
|
70
|
+
index_content = 0;
|
|
71
|
+
}
|
|
72
|
+
if (i == 0) {
|
|
73
|
+
first_occur = index_content;
|
|
74
|
+
}
|
|
75
|
+
// content_index.push({index_content:index_content, keyword_len:keyword_len});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
isMatch = false;
|
|
80
|
+
}
|
|
81
|
+
// show search results
|
|
82
|
+
if (isMatch) {
|
|
83
|
+
str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
|
|
84
|
+
var content = data.content.trim().replace(/<[^>]+>/g, "");
|
|
85
|
+
if (first_occur >= 0) {
|
|
86
|
+
// cut out 100 characters
|
|
87
|
+
var start = first_occur - 20;
|
|
88
|
+
var end = first_occur + 80;
|
|
89
|
+
|
|
90
|
+
if (start < 0) {
|
|
91
|
+
start = 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (start == 0) {
|
|
95
|
+
end = 100;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (end > content.length) {
|
|
99
|
+
end = content.length;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var match_content = content.substr(start, end);
|
|
103
|
+
|
|
104
|
+
// highlight all keywords
|
|
105
|
+
keywords.forEach(function (keyword) {
|
|
106
|
+
var regS = new RegExp(keyword, "gi");
|
|
107
|
+
match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
str += "<p class=\"search-result\">" + match_content + "...</p>"
|
|
111
|
+
}
|
|
112
|
+
str += "</li>";
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
str += "</ul>";
|
|
116
|
+
if (str.indexOf('<li>') === -1) {
|
|
117
|
+
return $resultContent.innerHTML = BTN + "<div class=\"search-result-empty\"><p><i class=\"fe fe-tired\"></i> 没有找到内容,更换下搜索词试试吧~<p></div>";
|
|
118
|
+
}
|
|
119
|
+
$resultContent.innerHTML = BTN + str;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
$(document).on('click', '#local-search-close', function () {
|
|
124
|
+
$('#local-search-input').val('');
|
|
125
|
+
$('#local-search-result').html('');
|
|
126
|
+
});
|
|
127
127
|
};
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
// 随机句子功能
|
|
2
|
-
(function() {
|
|
3
|
-
// 默认句子库(备用)
|
|
4
|
-
const defaultSentences = [
|
|
5
|
-
"生活就像一盒巧克力,你永远不知道下一颗是什么味道。",
|
|
6
|
-
"人生没有彩排,每一天都是现场直播。",
|
|
7
|
-
"时间是最好的老师,但遗憾的是,它杀死了所有的学生。",
|
|
8
|
-
"成功不是偶然的,而是必然的。",
|
|
9
|
-
"每一个优秀的人,都有一段沉默的时光。",
|
|
10
|
-
"人生就像一场旅行,不必在乎目的地,在乎的是沿途的风景。",
|
|
11
|
-
"梦想还是要有的,万一实现了呢?",
|
|
12
|
-
"没有人能回到过去重新开始,但谁都可以从现在开始,书写一个全然不同的结局。",
|
|
13
|
-
"生活不是等待暴风雨过去,而是学会在雨中跳舞。",
|
|
14
|
-
"最困难的时刻,也是离成功最近的时刻。",
|
|
15
|
-
"每一次的失败,都是成功的垫脚石。",
|
|
16
|
-
"人生最大的敌人是自己的懒惰。",
|
|
17
|
-
"没有人能替你承担生活的责任,也没有人能阻挡你走向成功。",
|
|
18
|
-
"时间会证明一切,但前提是你得给时间时间。",
|
|
19
|
-
"成功不是将来才有的,而是从决定去做的那一刻起,持续累积而成。",
|
|
20
|
-
"每一个不曾起舞的日子,都是对生命的辜负。",
|
|
21
|
-
"人生就像爬山,看起来走了很远,一抬头才发现还在山脚下。",
|
|
22
|
-
"没有人能随随便便成功,它来自彻底的自我管理和毅力。",
|
|
23
|
-
"生活不会亏待每一个努力的人。",
|
|
24
|
-
"最怕你一生碌碌无为,还安慰自己平凡可贵。"
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
let sentences = [...defaultSentences]; // 当前使用的句子库
|
|
28
|
-
let useLocalFile = true; // 是否使用本地txt文件
|
|
29
|
-
let queueSize = 5; // 防重复队列大小,默认5
|
|
30
|
-
let recentSentences = []; // 最近显示的句子队列
|
|
31
|
-
|
|
32
|
-
// 检查配置选项(通过全局变量或数据属性)
|
|
33
|
-
function checkConfig() {
|
|
34
|
-
// 尝试从页面元素获取配置
|
|
35
|
-
const configElement = document.querySelector('[data-random-sentences-config]');
|
|
36
|
-
if (configElement) {
|
|
37
|
-
try {
|
|
38
|
-
const config = JSON.parse(configElement.getAttribute('data-random-sentences-config'));
|
|
39
|
-
if (config.hasOwnProperty('use_local_file')) {
|
|
40
|
-
useLocalFile = config.use_local_file;
|
|
41
|
-
}
|
|
42
|
-
if (config.hasOwnProperty('queue_size') && config.queue_size > 0) {
|
|
43
|
-
queueSize = config.queue_size;
|
|
44
|
-
}
|
|
45
|
-
} catch (e) {
|
|
46
|
-
console.log('解析配置失败,使用默认设置');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 从txt文件读取句子
|
|
52
|
-
async function loadSentencesFromFile() {
|
|
53
|
-
try {
|
|
54
|
-
const response = await fetch('/data/random-sentences.txt');
|
|
55
|
-
if (response.ok) {
|
|
56
|
-
const text = await response.text();
|
|
57
|
-
// 过滤空行和以#开头的注释行
|
|
58
|
-
const lines = text.split('\n').filter(line => {
|
|
59
|
-
const trimmed = line.trim();
|
|
60
|
-
return trimmed !== '' && !trimmed.startsWith('#');
|
|
61
|
-
});
|
|
62
|
-
if (lines.length > 0) {
|
|
63
|
-
sentences = lines;
|
|
64
|
-
console.log('成功从txt文件加载句子库,共', lines.length, '句');
|
|
65
|
-
} else {
|
|
66
|
-
console.log('txt文件为空,使用默认句子库');
|
|
67
|
-
sentences = [...defaultSentences];
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
console.log('无法读取txt文件,使用默认句子库');
|
|
71
|
-
sentences = [...defaultSentences];
|
|
72
|
-
}
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.log('读取txt文件失败,使用默认句子库:', error);
|
|
75
|
-
sentences = [...defaultSentences];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 随机选择句子的函数(防重复版本)
|
|
80
|
-
function getRandomSentence() {
|
|
81
|
-
// 如果句子库数量小于等于队列大小,直接随机选择
|
|
82
|
-
if (sentences.length <= queueSize) {
|
|
83
|
-
const randomIndex = Math.floor(Math.random() * sentences.length);
|
|
84
|
-
const selectedSentence = sentences[randomIndex];
|
|
85
|
-
// 更新队列
|
|
86
|
-
updateRecentQueue(selectedSentence);
|
|
87
|
-
return selectedSentence;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 获取不在最近队列中的句子
|
|
91
|
-
const availableSentences = sentences.filter(sentence => !recentSentences.includes(sentence));
|
|
92
|
-
|
|
93
|
-
// 如果所有句子都在队列中,清空队列重新开始
|
|
94
|
-
if (availableSentences.length === 0) {
|
|
95
|
-
recentSentences = [];
|
|
96
|
-
const randomIndex = Math.floor(Math.random() * sentences.length);
|
|
97
|
-
const selectedSentence = sentences[randomIndex];
|
|
98
|
-
updateRecentQueue(selectedSentence);
|
|
99
|
-
return selectedSentence;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 从可用句子中随机选择
|
|
103
|
-
const randomIndex = Math.floor(Math.random() * availableSentences.length);
|
|
104
|
-
const selectedSentence = availableSentences[randomIndex];
|
|
105
|
-
|
|
106
|
-
// 更新队列
|
|
107
|
-
updateRecentQueue(selectedSentence);
|
|
108
|
-
|
|
109
|
-
return selectedSentence;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 更新最近显示句子队列
|
|
113
|
-
function updateRecentQueue(sentence) {
|
|
114
|
-
// 如果句子已经在队列中,先移除
|
|
115
|
-
const index = recentSentences.indexOf(sentence);
|
|
116
|
-
if (index > -1) {
|
|
117
|
-
recentSentences.splice(index, 1);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 将新句子添加到队列末尾
|
|
121
|
-
recentSentences.push(sentence);
|
|
122
|
-
|
|
123
|
-
// 如果队列超过设定大小,移除最旧的句子
|
|
124
|
-
if (recentSentences.length > queueSize) {
|
|
125
|
-
recentSentences.shift();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// 处理句子中的空格(单空格保持,双空格及以上换行)
|
|
130
|
-
function processSentence(sentence) {
|
|
131
|
-
return sentence.replace(/ +/g, '<br>');
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// 显示随机句子
|
|
135
|
-
function displayRandomSentence() {
|
|
136
|
-
const sentenceElement = document.getElementById('random-sentence');
|
|
137
|
-
if (sentenceElement) {
|
|
138
|
-
const randomSentence = getRandomSentence();
|
|
139
|
-
const processedSentence = processSentence(randomSentence);
|
|
140
|
-
sentenceElement.innerHTML = processedSentence;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// 初始化:先尝试加载txt文件,然后显示随机句子
|
|
145
|
-
async function initialize() {
|
|
146
|
-
checkConfig(); // 检查配置
|
|
147
|
-
if (useLocalFile) {
|
|
148
|
-
await loadSentencesFromFile();
|
|
149
|
-
}
|
|
150
|
-
displayRandomSentence();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 页面加载完成后初始化
|
|
154
|
-
if (document.readyState === 'loading') {
|
|
155
|
-
document.addEventListener('DOMContentLoaded', initialize);
|
|
156
|
-
} else {
|
|
157
|
-
initialize();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 页面刷新时重新选择句子(通过监听页面可见性变化)
|
|
161
|
-
document.addEventListener('visibilitychange', function() {
|
|
162
|
-
if (!document.hidden) {
|
|
163
|
-
displayRandomSentence();
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
})();
|