hexo-theme-solitude 1.3.1 → 1.4.0
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/.github/FUNDING.yml +13 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +107 -0
- package/.github/ISSUE_TEMPLATE/config.yml +13 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +14 -0
- package/.github/workflows/npm-publish.yml +21 -0
- package/CONTRIBUTING.md +0 -0
- package/LICENSE +0 -0
- package/README.md +60 -43
- package/README_EN.md +60 -42
- package/_config.yml +606 -451
- package/languages/en-US.yml +3 -23
- package/languages/zh-CN.yml +3 -23
- package/layout/404.pug +0 -0
- package/layout/archive.pug +0 -0
- package/layout/category.pug +0 -0
- package/layout/includes/body/mode.pug +1 -6
- package/layout/includes/console.pug +3 -3
- package/layout/includes/footer.pug +16 -15
- package/layout/includes/head/config.pug +38 -30
- package/layout/includes/head/opengraph.pug +0 -0
- package/layout/includes/head/pwa.pug +5 -44
- package/layout/includes/head.pug +3 -1
- package/layout/includes/header.pug +0 -0
- package/layout/includes/inject/body.pug +114 -65
- package/layout/includes/inject/head.pug +11 -46
- package/layout/includes/layout.pug +1 -2
- package/layout/includes/loading.pug +0 -0
- package/layout/includes/mixins/articleSort.pug +0 -0
- package/layout/includes/mixins/pagination.pug +0 -0
- package/layout/includes/nav.pug +1 -1
- package/layout/includes/page/about.pug +1 -1
- package/layout/includes/page/categories.pug +0 -0
- package/layout/includes/page/default.pug +0 -0
- package/layout/includes/page/equipment.pug +0 -0
- package/layout/includes/page/links.pug +2 -2
- package/layout/includes/page/music.pug +0 -0
- package/layout/includes/page/not_configured.pug +0 -0
- package/layout/includes/page/rss.pug +3 -3
- package/layout/includes/page/says.pug +15 -15
- package/layout/includes/page/tags.pug +0 -0
- package/layout/includes/page/tlink.pug +1 -0
- package/layout/includes/recent-posts.pug +0 -0
- package/layout/includes/sidebar.pug +0 -0
- package/layout/includes/widgets/aside/aside.pug +6 -6
- package/layout/includes/widgets/aside/asideAllInfo.pug +0 -0
- package/layout/includes/widgets/aside/asideArchive.pug +0 -0
- package/layout/includes/widgets/aside/asideCustom.pug +1 -1
- package/layout/includes/widgets/aside/asideFlipCard.pug +0 -0
- package/layout/includes/widgets/aside/asideInfoCard.pug +3 -3
- package/layout/includes/widgets/aside/asideNewestPost.pug +0 -0
- package/layout/includes/widgets/aside/asideSwitch.pug +0 -4
- package/layout/includes/widgets/aside/asideTag.pug +1 -1
- package/layout/includes/widgets/aside/asideToc.pug +0 -0
- package/layout/includes/widgets/aside/asideWebInfo.pug +2 -2
- package/layout/includes/widgets/home/banner.pug +0 -0
- package/layout/includes/widgets/home/bb/json.pug +22 -0
- package/layout/includes/widgets/home/bb/local.pug +17 -0
- package/layout/includes/widgets/home/bb/memos.pug +25 -0
- package/layout/includes/widgets/home/bbTimeList.pug +11 -7
- package/layout/includes/widgets/home/categoryBar.pug +0 -0
- package/layout/includes/widgets/home/categoryGroup.pug +1 -1
- package/layout/includes/widgets/home/hometop.pug +0 -0
- package/layout/includes/widgets/home/postList.pug +0 -0
- package/layout/includes/widgets/home/topGroup.pug +0 -0
- package/layout/includes/widgets/nav/left.pug +0 -0
- package/layout/includes/widgets/nav/menu.pug +1 -1
- package/layout/includes/widgets/nav/right.pug +6 -5
- package/layout/includes/widgets/page/about/authorinfo.pug +10 -9
- package/layout/includes/widgets/page/about/award.pug +0 -0
- package/layout/includes/widgets/page/about/contentinfo.pug +35 -34
- package/layout/includes/widgets/page/about/hobbies.pug +21 -17
- package/layout/includes/widgets/page/about/motto.pug +17 -16
- package/layout/includes/widgets/page/about/other.pug +16 -16
- package/layout/includes/widgets/page/about/personalities.pug +15 -14
- package/layout/includes/widgets/page/about/skillsinfo.pug +37 -36
- package/layout/includes/widgets/page/about/tenyear.pug +0 -0
- package/layout/includes/widgets/page/banner.pug +9 -3
- package/layout/includes/widgets/page/equipment/content.pug +0 -0
- package/layout/includes/widgets/page/links/banner.pug +14 -12
- package/layout/includes/widgets/page/links/linksCard.pug +4 -6
- package/layout/includes/widgets/page/links/linksDiscn.pug +8 -0
- package/layout/includes/widgets/page/links/linksItem.pug +4 -6
- package/layout/includes/widgets/page/says/json.pug +80 -0
- package/layout/includes/widgets/page/says/local.pug +48 -0
- package/layout/includes/widgets/page/says/memos.pug +109 -0
- package/layout/includes/widgets/post/award.pug +0 -0
- package/layout/includes/widgets/post/copyright.pug +2 -2
- package/layout/includes/widgets/post/post-ai.pug +12 -0
- package/layout/includes/widgets/post/postMeta.pug +2 -2
- package/layout/includes/widgets/post/postNav.pug +0 -0
- package/layout/includes/widgets/post/wave.pug +0 -0
- package/layout/includes/widgets/randomlink.pug +1 -1
- package/layout/includes/widgets/rightside/index.pug +6 -5
- package/layout/includes/widgets/third-party/comments/comment.pug +1 -5
- package/layout/includes/widgets/third-party/comments/twikoo.pug +1 -1
- package/layout/includes/widgets/third-party/comments/waline.pug +9 -11
- package/layout/includes/widgets/third-party/music.pug +1 -1
- package/layout/includes/widgets/third-party/news-comment/newest-comment.pug +6 -0
- package/layout/includes/widgets/third-party/news-comment/twikoo.pug +70 -0
- package/layout/includes/widgets/third-party/news-comment/waline.pug +64 -0
- package/layout/includes/widgets/third-party/pjax.pug +0 -0
- package/layout/includes/widgets/third-party/search/algolia-search.pug +0 -0
- package/layout/includes/widgets/third-party/search/index.pug +8 -7
- package/layout/includes/widgets/third-party/search/local-search.pug +0 -0
- package/layout/index.pug +3 -3
- package/layout/page.pug +0 -4
- package/layout/post.pug +2 -2
- package/layout/tag.pug +0 -0
- package/package.json +18 -9
- package/plugins.yml +109 -0
- package/scripts/event/cdn.js +129 -0
- package/scripts/event/init.js +0 -0
- package/scripts/event/page.js +1 -21
- package/scripts/event/welcome.js +1 -1
- package/scripts/filter/checkThemeConfig.js +0 -0
- package/scripts/filter/default.js +0 -0
- package/scripts/filter/lazyload.js +1 -1
- package/scripts/filter/randomPosts.js +0 -0
- package/scripts/helper/cdn.js +0 -0
- package/scripts/helper/getArchiveLength.js +0 -0
- package/scripts/helper/page.js +0 -0
- package/scripts/helper/related_post.js +0 -0
- package/scripts/helper/stylus.js +0 -0
- package/scripts/tags/button.js +0 -0
- package/scripts/tags/bvideo.js +0 -0
- package/scripts/tags/card.js +0 -0
- package/scripts/tags/checkbox.js +0 -0
- package/scripts/tags/fold.js +0 -0
- package/scripts/tags/image.js +0 -0
- package/scripts/tags/inline-image.js +0 -0
- package/scripts/tags/label.js +0 -0
- package/scripts/tags/link.js +0 -0
- package/scripts/tags/media.js +0 -0
- package/scripts/tags/note.js +0 -0
- package/scripts/tags/span.js +0 -0
- package/scripts/tags/tabs.js +0 -0
- package/scripts/tags/timeline.js +0 -0
- package/scripts/tags/u.js +0 -0
- package/source/css/_global/animation.css +0 -0
- package/source/css/_global/function.styl +42 -42
- package/source/css/_global/index.styl +1 -1
- package/source/css/_global/var.styl +0 -0
- package/source/css/_layout/basic.styl +10 -12
- package/source/css/_layout/header.styl +7 -2
- package/source/css/_layout/index.styl +59 -5
- package/source/css/_mode/index.styl +1 -17
- package/source/css/_page/_home/category-bar.styl +0 -0
- package/source/css/_page/_home/home-top.styl +10 -31
- package/source/css/_page/_home/index.styl +0 -0
- package/source/css/_page/_home/pagination.styl +3 -0
- package/source/css/_page/_home/recent-post.styl +10 -3
- package/source/css/_page/about/index.styl +0 -0
- package/source/css/_page/about/tenyear.styl +0 -0
- package/source/css/_page/about.styl +9 -0
- package/source/css/_page/category.styl +0 -0
- package/source/css/_page/douban.styl +0 -1
- package/source/css/_page/equipment.styl +0 -0
- package/source/css/_page/error.styl +0 -0
- package/source/css/_page/home.styl +0 -0
- package/source/css/_page/index.styl +2 -3
- package/source/css/_page/links.styl +84 -49
- package/source/css/_page/moment.styl +0 -0
- package/source/css/_page/music.styl +0 -0
- package/source/css/_page/rss.styl +0 -0
- package/source/css/_page/says.styl +10 -0
- package/source/css/_page/tag.styl +0 -0
- package/source/css/_widgets/_aside/allinfo.styl +34 -0
- package/source/css/_widgets/_aside/flip.styl +0 -0
- package/source/css/_widgets/_aside/index.styl +1 -7
- package/source/css/_widgets/_aside/info.styl +0 -0
- package/source/css/_widgets/_aside/newPost.styl +0 -0
- package/source/css/_widgets/_aside/toc.styl +0 -0
- package/source/css/_widgets/_aside/welcome.styl +0 -0
- package/source/css/_widgets/_comment/index.styl +0 -0
- package/source/css/_widgets/_comment/twikoo.styl +0 -2
- package/source/css/_widgets/_comment/waline.styl +0 -0
- package/source/css/_widgets/_extra/console.styl +0 -0
- package/source/css/_widgets/_extra/fullpage.styl +0 -0
- package/source/css/_widgets/_extra/music.styl +1 -1
- package/source/css/_widgets/_extra/pace.styl +0 -0
- package/source/css/_widgets/_extra/rightmenu.styl +0 -0
- package/source/css/_widgets/_mixins/article-sort.styl +0 -0
- package/source/css/_widgets/_mixins/footer.styl +1 -2
- package/source/css/_widgets/_mixins/other.styl +0 -4
- package/source/css/_widgets/_mixins/sidebar.styl +0 -0
- package/source/css/_widgets/_post/_highlight/diff.styl +0 -0
- package/source/css/_widgets/_post/_highlight/index.styl +0 -1
- package/source/css/_widgets/_post/_highlight/theme/default.styl +0 -0
- package/source/css/_widgets/_post/_highlight/theme/mac.styl +0 -0
- package/source/css/_widgets/_post/_highlight/theme.styl +0 -0
- package/source/css/_widgets/_post/commentBarrage.styl +0 -0
- package/source/css/_widgets/_post/content.styl +42 -11
- package/source/css/_widgets/_post/copyright.styl +0 -0
- package/source/css/_widgets/_post/index.styl +1 -1
- package/source/css/_widgets/_post/meta.styl +0 -3
- package/source/css/_widgets/_post/pagination.styl +1 -1
- package/source/css/_widgets/_post/postAI.styl +0 -0
- package/source/css/_widgets/_post/relatedPost.styl +0 -0
- package/source/css/_widgets/_post/tools.styl +0 -0
- package/source/css/_widgets/_search/algolia-search.styl +0 -0
- package/source/css/_widgets/_search/local-search.styl +0 -0
- package/source/css/_widgets/_tags/button.styl +0 -0
- package/source/css/_widgets/_tags/bvideo.styl +0 -0
- package/source/css/_widgets/_tags/card.styl +0 -0
- package/source/css/_widgets/_tags/checkbox.styl +0 -0
- package/source/css/_widgets/_tags/fold.styl +0 -0
- package/source/css/_widgets/_tags/image.styl +0 -0
- package/source/css/_widgets/_tags/index.styl +0 -0
- package/source/css/_widgets/_tags/inline-image.styl +0 -0
- package/source/css/_widgets/_tags/label.styl +0 -0
- package/source/css/_widgets/_tags/link.styl +4 -2
- package/source/css/_widgets/_tags/note.styl +0 -0
- package/source/css/_widgets/_tags/span.styl +0 -0
- package/source/css/_widgets/_tags/tabs.styl +0 -0
- package/source/css/_widgets/_tags/timeline.styl +0 -1
- package/source/css/_widgets/index.styl +4 -4
- package/source/css/index.styl +0 -0
- package/source/img/avatar.png +0 -0
- package/source/img/default.png +0 -0
- package/source/img/error_load.png +0 -0
- package/source/js/{extend/comment/twikoo/commentBarrage.js → comment/twikoo_commentBarrage.js} +0 -0
- package/source/js/{extend/comment/waline/commentBarrage.js → comment/waline_commentBarrage.js} +0 -0
- package/source/js/covercolor/api.js +95 -0
- package/source/js/covercolor/local.js +154 -0
- package/source/js/main.js +28 -235
- package/source/js/music.js +0 -0
- package/source/js/rightside.js +404 -0
- package/source/js/{extend/search/algolia-search.js → search/algolia.js} +10 -0
- package/source/js/{extend/search/local-search.js → search/local.js} +24 -2
- package/source/js/utils.js +75 -1
- package/layout/includes/head/fest.pug +0 -22
- package/layout/includes/page/echarts.pug +0 -7
- package/layout/includes/page/moments.pug +0 -4
- package/layout/includes/widgets/aside/asideHistory.pug +0 -8
- package/layout/includes/widgets/aside/asideWelcome.pug +0 -12
- package/layout/includes/widgets/page/moments/angle.pug +0 -19
- package/layout/includes/widgets/page/moments/index.pug +0 -23
- package/layout/includes/widgets/page/says/saysBottom.pug +0 -11
- package/layout/includes/widgets/page/says/saysContent.pug +0 -6
- package/layout/includes/widgets/page/says/saysFunction.pug +0 -10
- package/layout/includes/widgets/page/says/saysMeta.pug +0 -7
- package/layout/includes/widgets/third-party/ai/index.pug +0 -12
- package/layout/includes/widgets/third-party/comments/gitalk.pug +0 -0
- package/layout/includes/widgets/third-party/comments/valine.pug +0 -0
- package/scripts/helper/echarts.js +0 -407
- package/source/css/_widgets/_aside/history.styl +0 -42
- package/source/js/extend/comment/twikoo/twikoo.js +0 -67
- package/source/js/extend/comment/waline/waline.js +0 -60
- package/source/lib/bundle.min.js +0 -27
- package/source/lib/circle.min.js +0 -1
- package/source/lib/cover-color.min.js +0 -7
- package/source/lib/friends_post.js +0 -4
- package/source/lib/lazyload.min.js +0 -1
- package/source/lib/rightside.min.js +0 -1
- package/source/lib/snackbar.min.css +0 -1
- package/source/lib/snackbar.min.js +0 -9
- package/source/lib/txmap.min.js +0 -1
- package/source/lib/universe.min.js +0 -1
- package/source/lib/view-image.min.js +0 -6
- package/source/lib/waterfall.min.js +0 -1
- /package/source/{lib → js}/sco-ai.min.js +0 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
const coverColor = () => {
|
2
|
+
const path = document.getElementById("post-cover")?.src;
|
3
|
+
if (path) {
|
4
|
+
handleApiColor(path);
|
5
|
+
}
|
6
|
+
}
|
7
|
+
|
8
|
+
function handleApiColor(path) {
|
9
|
+
const cacheGroup = JSON.parse(localStorage.getItem('Solitude')) || {};
|
10
|
+
if (cacheGroup.postcolor && cacheGroup.postcolor[path]) {
|
11
|
+
const color = cacheGroup.postcolor[path].value;
|
12
|
+
const [r, g, b] = color.match(/\w\w/g).map(x => parseInt(x, 16));
|
13
|
+
setThemeColors(color, r, g, b);
|
14
|
+
} else {
|
15
|
+
img2color(path);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
function img2color(src) {
|
20
|
+
const apiUrl = coverColorConfig.api + encodeURIComponent(src);
|
21
|
+
|
22
|
+
fetch(apiUrl)
|
23
|
+
.then(response => response.json())
|
24
|
+
.then(data => {
|
25
|
+
const color = data.RGB;
|
26
|
+
const [r, g, b] = color.match(/\w\w/g).map(x => parseInt(x, 16));
|
27
|
+
setThemeColors(color, r, g, b);
|
28
|
+
if (coverColorConfig.time !== 0) {
|
29
|
+
cacheColor(src, color);
|
30
|
+
}
|
31
|
+
})
|
32
|
+
.catch(error => {
|
33
|
+
console.error('请检查API是否正常!\n' + error);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
|
37
|
+
function cacheColor(src, color) {
|
38
|
+
const expirationTime = Date.now() + coverColorConfig.time;
|
39
|
+
const cacheGroup = saveToLocal.get('Solitude') || {};
|
40
|
+
cacheGroup.postcolor = cacheGroup.postcolor || {};
|
41
|
+
cacheGroup.postcolor[src] = {value: color, expiration: expirationTime};
|
42
|
+
localStorage.setItem('Solitude', JSON.stringify(cacheGroup));
|
43
|
+
}
|
44
|
+
|
45
|
+
function setThemeColors(value, r = null, g = null, b = null) {
|
46
|
+
if (value) {
|
47
|
+
document.documentElement.style.setProperty('--sco-main', value);
|
48
|
+
document.documentElement.style.setProperty('--sco-main-op', value + '23');
|
49
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', value + 'dd');
|
50
|
+
document.documentElement.style.setProperty('--sco-main-none', value + '00');
|
51
|
+
|
52
|
+
if (r && g && b) {
|
53
|
+
var brightness = Math.round(((parseInt(r) * 299) + (parseInt(g) * 587) + (parseInt(b) * 114)) / 1000);
|
54
|
+
var cardContents = document.getElementsByClassName('card-content');
|
55
|
+
var authorInfo = document.getElementsByClassName('author-info__sayhi');
|
56
|
+
for (let i = 0; i < cardContents.length; i++) {
|
57
|
+
cardContents[i].style.setProperty('--sco-card-bg', 'var(--sco-white)');
|
58
|
+
}
|
59
|
+
|
60
|
+
for (let i = 0; i < authorInfo.length; i++) {
|
61
|
+
authorInfo[i].style.setProperty('background', 'var(--sco-white-op)');
|
62
|
+
authorInfo[i].style.setProperty('color', 'var(--sco-white)');
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
document.getElementById("coverdiv").classList.add("loaded");
|
67
|
+
initThemeColor();
|
68
|
+
} else {
|
69
|
+
document.documentElement.style.setProperty('--sco-main', 'var(--sco-theme)');
|
70
|
+
document.documentElement.style.setProperty('--sco-main-op', 'var(--sco-theme-op)');
|
71
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', 'var(--sco-theme-op-deep)');
|
72
|
+
document.documentElement.style.setProperty('--sco-main-none', 'var(--sco-theme-none)');
|
73
|
+
initThemeColor();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
function initThemeColor() {
|
78
|
+
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
79
|
+
let themeColor;
|
80
|
+
if (currentTop > 0) {
|
81
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-card-bg');
|
82
|
+
} else if (PAGE_CONFIG.is_post) {
|
83
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-main');
|
84
|
+
} else {
|
85
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-background');
|
86
|
+
}
|
87
|
+
changeThemeColor(themeColor);
|
88
|
+
}
|
89
|
+
|
90
|
+
function changeThemeColor(color) {
|
91
|
+
const meta = document.querySelector('meta[name="theme-color"]');
|
92
|
+
if (meta) {
|
93
|
+
meta.setAttribute('content', color);
|
94
|
+
}
|
95
|
+
}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
const coverColor = () => {
|
2
|
+
const path = document.getElementById("post-cover")?.src;
|
3
|
+
if (path) {
|
4
|
+
localColor(path);
|
5
|
+
}
|
6
|
+
}
|
7
|
+
|
8
|
+
const localColor = (path) => {
|
9
|
+
const img = new Image();
|
10
|
+
img.crossOrigin = "Anonymous";
|
11
|
+
img.onload = function () {
|
12
|
+
const canvas = document.createElement("canvas");
|
13
|
+
canvas.width = img.width;
|
14
|
+
canvas.height = img.height;
|
15
|
+
const ctx = canvas.getContext("2d");
|
16
|
+
ctx.drawImage(img, 0, 0);
|
17
|
+
const data = ctx.getImageData(0, 0, img.width, img.height).data;
|
18
|
+
const {r, g, b} = calculateRGB(data);
|
19
|
+
let value = rgbToHex(r, g, b);
|
20
|
+
if (getContrastYIQ(value) === "light") {
|
21
|
+
value = LightenDarkenColor(value, -50);
|
22
|
+
}
|
23
|
+
setThemeColors(value, r, g, b);
|
24
|
+
};
|
25
|
+
img.onerror = function() {
|
26
|
+
console.error('图片加载失败');
|
27
|
+
};
|
28
|
+
img.src = path;
|
29
|
+
}
|
30
|
+
|
31
|
+
function calculateRGB(data) {
|
32
|
+
let r = 0, g = 0, b = 0;
|
33
|
+
const step = 5;
|
34
|
+
for (let i = 0; i < data.length; i += 4 * step) {
|
35
|
+
r += data[i];
|
36
|
+
g += data[i + 1];
|
37
|
+
b += data[i + 2];
|
38
|
+
}
|
39
|
+
r = Math.floor(r / (data.length / 4 / step));
|
40
|
+
g = Math.floor(g / (data.length / 4 / step));
|
41
|
+
b = Math.floor(b / (data.length / 4 / step));
|
42
|
+
return {r, g, b};
|
43
|
+
}
|
44
|
+
|
45
|
+
function rgbToHex(r, g, b) {
|
46
|
+
return "#" + [r, g, b].map(x => x.toString(16).padStart(2, '0')).join('');
|
47
|
+
}
|
48
|
+
|
49
|
+
function LightenDarkenColor(col, amt) {
|
50
|
+
let usePound = false;
|
51
|
+
|
52
|
+
if (col[0] === "#") {
|
53
|
+
col = col.slice(1);
|
54
|
+
usePound = true;
|
55
|
+
}
|
56
|
+
|
57
|
+
const num = parseInt(col, 16);
|
58
|
+
const r = Math.min(255, Math.max(0, (num >> 16) + amt));
|
59
|
+
const b = Math.min(255, Math.max(0, ((num >> 8) & 0xff) + amt));
|
60
|
+
const g = Math.min(255, Math.max(0, (num & 0xff) + amt));
|
61
|
+
|
62
|
+
return `${usePound ? "#" : ""}${(g | (b << 8) | (r << 16)).toString(16).padStart(6, "0")}`;
|
63
|
+
}
|
64
|
+
|
65
|
+
function getContrastYIQ(hexcolor) {
|
66
|
+
var colorrgb = colorRgb(hexcolor);
|
67
|
+
var colors = colorrgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
68
|
+
var red = colors[1];
|
69
|
+
var green = colors[2];
|
70
|
+
var blue = colors[3];
|
71
|
+
var brightness = (red * 299) + (green * 587) + (blue * 114);
|
72
|
+
brightness = brightness / 255000;
|
73
|
+
return brightness >= 0.5 ? "light" : "dark";
|
74
|
+
}
|
75
|
+
|
76
|
+
function colorRgb(str) {
|
77
|
+
const HEX_SHORT_REGEX = /^#([0-9a-fA-f]{3})$/;
|
78
|
+
const HEX_LONG_REGEX = /^#([0-9a-fA-f]{6})$/;
|
79
|
+
const HEX_SHORT_LENGTH = 4;
|
80
|
+
|
81
|
+
if (!str || typeof str !== 'string') {
|
82
|
+
return str;
|
83
|
+
}
|
84
|
+
|
85
|
+
const sColor = str.toLowerCase();
|
86
|
+
let hexValue = "";
|
87
|
+
|
88
|
+
if (sColor && (HEX_SHORT_REGEX.test(sColor) || HEX_LONG_REGEX.test(sColor))) {
|
89
|
+
hexValue = sColor.length === HEX_SHORT_LENGTH ?
|
90
|
+
sColor.replace(/^#(.)/g, "#$1$1") :
|
91
|
+
sColor;
|
92
|
+
|
93
|
+
const rgbValue = hexValue.slice(1)
|
94
|
+
.match(/.{2}/g)
|
95
|
+
.map(val => parseInt(val, 16));
|
96
|
+
|
97
|
+
return `rgb(${rgbValue[0]}, ${rgbValue[1]}, ${rgbValue[2]})`;
|
98
|
+
} else {
|
99
|
+
return sColor;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
function setThemeColors(value, r = null, g = null, b = null) {
|
104
|
+
const cardContents = document.getElementsByClassName('card-content');
|
105
|
+
const authorInfo = document.getElementsByClassName('author-info__sayhi');
|
106
|
+
|
107
|
+
if (value) {
|
108
|
+
document.documentElement.style.setProperty('--sco-main', value);
|
109
|
+
document.documentElement.style.setProperty('--sco-main-op', value + '23');
|
110
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', value + 'dd');
|
111
|
+
document.documentElement.style.setProperty('--sco-main-none', value + '00');
|
112
|
+
|
113
|
+
if (r && g && b) {
|
114
|
+
var brightness = Math.round(((parseInt(r) * 299) + (parseInt(g) * 587) + (parseInt(b) * 114)) / 1000);
|
115
|
+
for (let i = 0; i < cardContents.length; i++) {
|
116
|
+
cardContents[i].style.setProperty('--sco-card-bg', 'var(--sco-white)');
|
117
|
+
}
|
118
|
+
|
119
|
+
for (let i = 0; i < authorInfo.length; i++) {
|
120
|
+
authorInfo[i].style.setProperty('background', 'var(--sco-white-op)');
|
121
|
+
authorInfo[i].style.setProperty('color', 'var(--sco-white)');
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
document.getElementById("coverdiv").classList.add("loaded");
|
126
|
+
initThemeColor();
|
127
|
+
} else {
|
128
|
+
document.documentElement.style.setProperty('--sco-main', 'var(--sco-theme)');
|
129
|
+
document.documentElement.style.setProperty('--sco-main-op', 'var(--sco-theme-op)');
|
130
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', 'var(--sco-theme-op-deep)');
|
131
|
+
document.documentElement.style.setProperty('--sco-main-none', 'var(--sco-theme-none)');
|
132
|
+
initThemeColor();
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
function initThemeColor() {
|
137
|
+
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
138
|
+
let themeColor;
|
139
|
+
if (currentTop > 0) {
|
140
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-card-bg');
|
141
|
+
} else if (PAGE_CONFIG.is_post) {
|
142
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-main');
|
143
|
+
} else {
|
144
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-background');
|
145
|
+
}
|
146
|
+
changeThemeColor(themeColor);
|
147
|
+
}
|
148
|
+
|
149
|
+
function changeThemeColor(color) {
|
150
|
+
const meta = document.querySelector('meta[name="theme-color"]');
|
151
|
+
if (meta) {
|
152
|
+
meta.setAttribute('content', color);
|
153
|
+
}
|
154
|
+
}
|