hexo-theme-solitude 1.8.10 → 1.8.11
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/_config.yml +1 -0
- package/languages/default.yml +3 -0
- package/languages/en.yml +3 -0
- package/languages/zh-CN.yml +3 -0
- package/languages/zh-TW.yml +3 -0
- package/layout/includes/footer.pug +1 -1
- package/layout/includes/head/page_config.pug +1 -1
- package/layout/includes/inject/body.pug +5 -5
- package/layout/includes/inject/head.pug +1 -1
- package/layout/includes/page/music.pug +6 -1
- package/layout/includes/widgets/aside/asideWebInfo.pug +12 -4
- package/layout/includes/widgets/home/carousel.pug +27 -21
- package/layout/includes/widgets/post/post-ai.pug +2 -2
- package/layout/includes/widgets/post/postMeta.pug +6 -2
- package/layout/includes/widgets/third-party/comments/artalk.pug +3 -3
- package/layout/includes/widgets/third-party/comments/twikoo.pug +4 -2
- package/layout/includes/widgets/third-party/comments/valine.pug +5 -3
- package/layout/includes/widgets/third-party/comments/waline.pug +4 -2
- package/package.json +1 -1
- package/plugins.yml +5 -1
- package/source/css/_layout/header.styl +7 -6
- package/source/css/_page/_home/carousel.styl +73 -89
- package/source/css/_page/links.styl +1 -1
- package/source/js/barrage_comment.js +63 -70
- package/source/js/covercolor/api.js +35 -52
- package/source/js/covercolor/local.js +22 -27
- package/source/js/main.js +472 -567
- package/source/js/music.js +15 -5
- package/source/js/right_menu.js +38 -47
- package/source/js/search/local.js +16 -11
- package/source/js/utils.js +109 -136
@@ -1,84 +1,77 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
class Barrage {
|
2
|
+
constructor(comments) {
|
3
|
+
this.comments = comments;
|
4
|
+
this.dom = document.querySelector(".comment-barrage");
|
5
|
+
this.barrageList = [];
|
6
|
+
this.barrageIndex = 0;
|
7
|
+
this.barrageTimer = [];
|
8
|
+
this.hoverOnCommentBarrage = false;
|
9
|
+
this.init();
|
7
10
|
}
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
barrageTimer: [],
|
13
|
-
barrageList: [],
|
14
|
-
barrageIndex: 0,
|
15
|
-
dom: document.querySelector(".comment-barrage"),
|
16
|
-
maxBarrage: 1,
|
17
|
-
barrageTime: 5000
|
18
|
-
};
|
19
|
-
this.hoverOnCommentBarrage = false;
|
20
|
-
this.init();
|
21
|
-
}
|
22
|
-
|
23
|
-
filterAndFlatten(comments) {
|
24
|
-
return comments.flatMap(comment => comment.replies ? [comment, ...this.filterAndFlatten(comment.replies)] : [comment]);
|
25
|
-
}
|
12
|
+
filterAndFlatten = (comments) => {
|
13
|
+
return (comments.flatMap(comment => comment.replies ? [comment, ...this.filterAndFlatten(comment.replies)] : [comment]))
|
14
|
+
}
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
sanitizeContent(content) {
|
17
|
+
return content.replace(/(<([^>]+)>)/ig, '').trim();
|
18
|
+
}
|
30
19
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
20
|
+
createBarrageItem(comment) {
|
21
|
+
const content = this.sanitizeContent(comment.content);
|
22
|
+
if (!content) return false;
|
23
|
+
const element = document.createElement("div");
|
24
|
+
element.className = "comment-barrage-item";
|
25
|
+
element.innerHTML = `<div class="barrageHead"><a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">${GLOBAL_CONFIG.lang.barrage.title}</a><div class="barrageNick">${comment.nick}</div><img class="barrageAvatar" src="${GLOBAL_CONFIG.comment.avatar}/avatar/${comment.mailMd5}"/><a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();"><i class="solitude st-close-fill"></i></a></div><a class="barrageContent" href="${comment.id ? `javascript:sco.scrollTo(\'${comment.id}\')` : 'javascript:sco.scrollTo(\'post-comment\')'}">${content}</a>`;
|
26
|
+
this.dom.appendChild(element);
|
27
|
+
this.barrageTimer.push(element);
|
28
|
+
return true;
|
29
|
+
}
|
41
30
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
removeBarrageItem(element) {
|
32
|
+
element.classList.add("out");
|
33
|
+
setTimeout(() => this.dom.removeChild(element), 1000);
|
34
|
+
}
|
46
35
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
54
|
-
}
|
55
|
-
if (this.config.barrageTimer.length > Math.min(this.config.maxBarrage, this.config.barrageList.length) && !this.hoverOnCommentBarrage) {
|
56
|
-
this.removeBarrageItem(this.config.barrageTimer.shift());
|
36
|
+
manageBarrage() {
|
37
|
+
if (this.barrageList.length && !this.hoverOnCommentBarrage) {
|
38
|
+
if (!this.createBarrageItem(this.barrageList[this.barrageIndex])) {
|
39
|
+
this.barrageIndex = (this.barrageIndex + 1) % this.barrageList.length;
|
40
|
+
return this.manageBarrage();
|
57
41
|
}
|
42
|
+
this.barrageIndex = (this.barrageIndex + 1) % this.barrageList.length;
|
58
43
|
}
|
59
|
-
|
60
|
-
|
61
|
-
const storageSwitch = utils.saveToLocal.get("commentBarrageSwitch");
|
62
|
-
this.config.dom.style.display = storageSwitch ? "flex" : "none";
|
63
|
-
this.config.barrageList = this.filterAndFlatten(array);
|
64
|
-
this.config.dom.innerHTML = "";
|
65
|
-
clearInterval(this.commentInterval);
|
66
|
-
this.commentInterval = setInterval(() => this.manageBarrage(), this.config.barrageTime);
|
44
|
+
if (this.barrageTimer.length > Math.min(1, this.barrageList.length) && !this.hoverOnCommentBarrage) {
|
45
|
+
this.removeBarrageItem(this.barrageTimer.shift());
|
67
46
|
}
|
47
|
+
}
|
68
48
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
49
|
+
initBarrage() {
|
50
|
+
const storageSwitch = utils.saveToLocal.get("commentBarrageSwitch");
|
51
|
+
this.dom.style.display = storageSwitch ? "flex" : "none";
|
52
|
+
this.barrageList = this.filterAndFlatten(this.comments);
|
53
|
+
this.dom.innerHTML = "";
|
54
|
+
clearInterval(this.commentInterval);
|
55
|
+
this.commentInterval = setInterval(() => this.manageBarrage(), 5000);
|
56
|
+
}
|
74
57
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
58
|
+
init() {
|
59
|
+
this.initBarrage();
|
60
|
+
this.dom.addEventListener('mouseover', () => this.hoverOnCommentBarrage = true);
|
61
|
+
this.dom.addEventListener('mouseout', () => this.hoverOnCommentBarrage = false);
|
62
|
+
}
|
63
|
+
|
64
|
+
destroy() {
|
65
|
+
clearInterval(this.commentInterval);
|
66
|
+
this.dom.removeEventListener('mouseover', () => this.hoverOnCommentBarrage = true)
|
67
|
+
this.dom.removeEventListener('mouseout', () => this.hoverOnCommentBarrage = false)
|
68
|
+
this.dom.innerHTML = ""
|
81
69
|
}
|
70
|
+
}
|
82
71
|
|
83
|
-
|
72
|
+
function initializeCommentBarrage(array) {
|
73
|
+
if (array.length === 0) return;
|
74
|
+
let existingBarrage = window.currentBarrage;
|
75
|
+
if (existingBarrage) existingBarrage.destroy();
|
76
|
+
window.currentBarrage = new Barrage(array);
|
84
77
|
}
|
@@ -1,76 +1,59 @@
|
|
1
1
|
const coverColor = () => {
|
2
2
|
const path = document.getElementById("post-cover")?.src;
|
3
|
-
|
4
|
-
handleApiColor(path);
|
5
|
-
} else {
|
6
|
-
document.documentElement.style.setProperty('--efu-main', 'var(--efu-theme)');
|
7
|
-
document.documentElement.style.setProperty('--efu-main-op', 'var(--efu-theme-op)');
|
8
|
-
document.documentElement.style.setProperty('--efu-main-op-deep', 'var(--efu-theme-op-deep)');
|
9
|
-
document.documentElement.style.setProperty('--efu-main-none', 'var(--efu-theme-none)');
|
10
|
-
initThemeColor()
|
11
|
-
}
|
3
|
+
path ? handleApiColor(path) : setDefaultThemeColors();
|
12
4
|
}
|
13
5
|
|
14
6
|
function handleApiColor(path) {
|
15
7
|
const cacheGroup = JSON.parse(localStorage.getItem('Solitude')) || {};
|
16
|
-
|
17
|
-
const color = cacheGroup.postcolor[path].value;
|
18
|
-
const [r, g, b] = color.match(/\w\w/g).map(x => parseInt(x, 16));
|
19
|
-
setThemeColors(color, r, g, b);
|
20
|
-
} else {
|
21
|
-
img2color(path);
|
22
|
-
}
|
8
|
+
cacheGroup.postcolor && cacheGroup.postcolor[path] ? setThemeColors(cacheGroup.postcolor[path].value) : img2color(path);
|
23
9
|
}
|
24
10
|
|
25
11
|
function img2color(src) {
|
26
|
-
|
27
|
-
fetch(apiUrl)
|
12
|
+
fetch(coverColorConfig.api + encodeURIComponent(src))
|
28
13
|
.then(response => response.json())
|
29
14
|
.then(data => {
|
30
|
-
|
31
|
-
|
32
|
-
setThemeColors(color, r, g, b);
|
33
|
-
const expirationTime = Date.now() + coverColorConfig.time;
|
34
|
-
const cacheGroup = JSON.parse(localStorage.getItem('Solitude')) || {};
|
35
|
-
cacheGroup.postcolor = cacheGroup.postcolor || {};
|
36
|
-
cacheGroup.postcolor[src] = {value: color, expiration: expirationTime};
|
37
|
-
localStorage.setItem('Solitude', JSON.stringify(cacheGroup));
|
15
|
+
setThemeColors(data.RGB);
|
16
|
+
cacheColor(src, data.RGB);
|
38
17
|
})
|
39
|
-
.catch(error
|
40
|
-
console.error('API:error:', error);
|
41
|
-
});
|
18
|
+
.catch(console.error);
|
42
19
|
}
|
43
20
|
|
44
|
-
function setThemeColors(value
|
21
|
+
function setThemeColors(value) {
|
45
22
|
if (value) {
|
23
|
+
const [r, g, b] = value.match(/\w\w/g).map(x => parseInt(x, 16));
|
46
24
|
document.documentElement.style.setProperty('--efu-main', value);
|
47
25
|
document.documentElement.style.setProperty('--efu-main-op', value + '23');
|
48
26
|
document.documentElement.style.setProperty('--efu-main-op-deep', value + 'dd');
|
49
27
|
document.documentElement.style.setProperty('--efu-main-none', value + '00');
|
50
|
-
|
51
|
-
if (r && g && b) {
|
52
|
-
let brightness = Math.round(((parseInt(r) * 299) + (parseInt(g) * 587) + (parseInt(b) * 114)) / 1000);
|
53
|
-
if (brightness < 125) {
|
54
|
-
let cardContents = document.getElementsByClassName('card-content');
|
55
|
-
for (let i = 0; i < cardContents.length; i++) {
|
56
|
-
cardContents[i].style.setProperty('--efu-card-bg', 'var(--efu-white)');
|
57
|
-
}
|
58
|
-
|
59
|
-
let authorInfo = document.getElementsByClassName('author-info__sayhi');
|
60
|
-
for (let i = 0; i < authorInfo.length; i++) {
|
61
|
-
authorInfo[i].style.setProperty('background', 'var(--efu-white-op)');
|
62
|
-
authorInfo[i].style.setProperty('color', 'var(--efu-white)');
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
28
|
+
adjustBrightness(r, g, b);
|
67
29
|
document.getElementById("coverdiv").classList.add("loaded");
|
68
30
|
initThemeColor();
|
69
31
|
} else {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
32
|
+
setDefaultThemeColors();
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
function setDefaultThemeColors() {
|
37
|
+
document.documentElement.style.setProperty('--efu-main', 'var(--efu-theme)');
|
38
|
+
document.documentElement.style.setProperty('--efu-main-op', 'var(--efu-theme-op)');
|
39
|
+
document.documentElement.style.setProperty('--efu-main-op-deep', 'var(--efu-theme-op-deep)');
|
40
|
+
document.documentElement.style.setProperty('--efu-main-none', 'var(--efu-theme-none)');
|
41
|
+
initThemeColor();
|
42
|
+
}
|
43
|
+
|
44
|
+
function cacheColor(src, color) {
|
45
|
+
const cacheGroup = JSON.parse(localStorage.getItem('Solitude')) || {};
|
46
|
+
cacheGroup.postcolor = cacheGroup.postcolor || {};
|
47
|
+
cacheGroup.postcolor[src] = {value: color, expiration: Date.now() + coverColorConfig.time};
|
48
|
+
localStorage.setItem('Solitude', JSON.stringify(cacheGroup));
|
49
|
+
}
|
50
|
+
|
51
|
+
function adjustBrightness(r, g, b) {
|
52
|
+
if (Math.round(((r * 299) + (g * 587) + (b * 114)) / 1000) < 125) {
|
53
|
+
[...document.getElementsByClassName('card-content')].forEach(item => item.style.setProperty('--efu-card-bg', 'var(--efu-white)'));
|
54
|
+
[...document.getElementsByClassName('author-info__sayhi')].forEach(item => {
|
55
|
+
item.style.setProperty('background', 'var(--efu-white-op)');
|
56
|
+
item.style.setProperty('color', 'var(--efu-white)');
|
57
|
+
});
|
75
58
|
}
|
76
59
|
}
|
@@ -1,39 +1,34 @@
|
|
1
1
|
const coverColor = () => {
|
2
2
|
const path = document.getElementById("post-cover")?.src;
|
3
|
-
|
4
|
-
localColor(path);
|
5
|
-
} else {
|
6
|
-
document.documentElement.style.setProperty('--efu-main', 'var(--efu-theme)');
|
7
|
-
document.documentElement.style.setProperty('--efu-main-op', 'var(--efu-theme-op)');
|
8
|
-
document.documentElement.style.setProperty('--efu-main-op-deep', 'var(--efu-theme-op-deep)');
|
9
|
-
document.documentElement.style.setProperty('--efu-main-none', 'var(--efu-theme-none)');
|
10
|
-
initThemeColor()
|
11
|
-
}
|
3
|
+
path ? localColor(path) : setDefaultThemeColors();
|
12
4
|
}
|
13
5
|
|
14
|
-
|
6
|
+
function setDefaultThemeColors() {
|
7
|
+
document.documentElement.style.setProperty('--efu-main', 'var(--efu-theme)');
|
8
|
+
document.documentElement.style.setProperty('--efu-main-op', 'var(--efu-theme-op)');
|
9
|
+
document.documentElement.style.setProperty('--efu-main-op-deep', 'var(--efu-theme-op-deep)');
|
10
|
+
document.documentElement.style.setProperty('--efu-main-none', 'var(--efu-theme-none)');
|
11
|
+
initThemeColor();
|
12
|
+
}
|
13
|
+
|
14
|
+
const localColor = path => {
|
15
15
|
const img = new Image();
|
16
16
|
img.crossOrigin = "Anonymous";
|
17
|
-
img.onload =
|
18
|
-
|
19
|
-
canvas.width = img.width;
|
20
|
-
canvas.height = img.height;
|
21
|
-
const ctx = canvas.getContext("2d");
|
22
|
-
ctx.drawImage(img, 0, 0);
|
23
|
-
const data = ctx.getImageData(0, 0, img.width, img.height).data;
|
24
|
-
const {r, g, b} = calculateRGB(data);
|
25
|
-
let value = rgbToHex(r, g, b);
|
26
|
-
if (getContrastYIQ(value) === "light") {
|
27
|
-
value = LightenDarkenColor(value, -50);
|
28
|
-
}
|
29
|
-
setThemeColors(value, r, g, b);
|
30
|
-
};
|
31
|
-
img.onerror = function () {
|
32
|
-
console.error('Image Error');
|
33
|
-
};
|
17
|
+
img.onload = () => setThemeColors(calculateColor(img));
|
18
|
+
img.onerror = () => console.error('Image Error');
|
34
19
|
img.src = path;
|
35
20
|
}
|
36
21
|
|
22
|
+
const calculateColor = img => {
|
23
|
+
const canvas = document.createElement("canvas");
|
24
|
+
const ctx = canvas.getContext("2d");
|
25
|
+
ctx.drawImage(img, 0, 0);
|
26
|
+
const data = ctx.getImageData(0, 0, img.width, img.height).data;
|
27
|
+
const {r, g, b} = calculateRGB(data);
|
28
|
+
let value = rgbToHex(r, g, b);
|
29
|
+
return getContrastYIQ(value) === "light" ? LightenDarkenColor(value, -50) : value;
|
30
|
+
}
|
31
|
+
|
37
32
|
function calculateRGB(data) {
|
38
33
|
let r = 0, g = 0, b = 0;
|
39
34
|
const step = 5;
|