From 85f010d6aa21ddd9769079bf4f9e3159d80af1af Mon Sep 17 00:00:00 2001 From: Spirit Date: Sat, 11 Apr 2020 23:08:16 +0800 Subject: [PATCH] perf: optimize --- js/sakura-app.js | 56 +++++++++++++++++------------------------------- style.css | 11 +++++++++- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/js/sakura-app.js b/js/sakura-app.js index 9ff612b..9bbd6ed 100644 --- a/js/sakura-app.js +++ b/js/sakura-app.js @@ -79,14 +79,21 @@ function post_list_show_animation() { function callback(entries) { entries.forEach((article) => { - if (article.target.classList.contains("post-list-show")) { + if (!window.IntersectionObserver) { article.target.style.willChange = 'auto'; - io.unobserve(article.target) - } else { - if (article.isIntersecting) { + if( article.target.classList.contains("post-list-show") === false){ article.target.classList.add("post-list-show"); + } + } else { + if (article.target.classList.contains("post-list-show")) { article.target.style.willChange = 'auto'; io.unobserve(article.target) + } else { + if (article.isIntersecting) { + article.target.classList.add("post-list-show"); + article.target.style.willChange = 'auto'; + io.unobserve(article.target) + } } } }) @@ -325,46 +332,26 @@ function checkBgImgCookie() { function checkDarkModeCookie() { var dark = getCookie("dark"), - today = new Date() - cWidth = document.body.clientWidth; - if (!dark) { - if ((today.getHours() > 21 || today.getHours() < 7)) { + today = new Date(), + hour = today.getHours(); + if ((!dark && (hour > 21 || hour < 7) ) || (dark == '1' && (hour >= 22 || hour <= 6))) { setTimeout(function () { $("#dark-bg").click(); }, 100); + $("#moblieDarkLight").html(''); console.log('夜间模式开启'); } else { - if (cWidth > 860) { + if (document.body.clientWidth > 860) { setTimeout(function () { checkBgImgCookie(); }, 100); - console.log('夜间模式关闭'); } else { $("html").css("background", "unset"); $("body").removeClass("dark"); $("#moblieDarkLight").html(''); setCookie("dark", "0", 0.33); } - } - } else { - if (dark == '1' && (today.getHours() >= 22 || today.getHours() <= 6)) { - setTimeout(function () { - $("#dark-bg").click(); - }, 100); - console.log('夜间模式开启'); - } else if (dark == '0' || today.getHours() < 22 || today.getHours() > 6) { - if (cWidth > 860) { - setTimeout(function () { - checkBgImgCookie(); - }, 100); - console.log('夜间模式关闭'); - } else { - $("html").css("background", "unset"); - $("body").removeClass("dark"); - $("#moblieDarkLight").html(''); - setCookie("dark", "0", 0.33); - } - } + console.log('夜间模式关闭'); } } if (!getCookie("darkcache") && (new Date().getHours() > 21 || new Date().getHours() < 7)) { @@ -497,12 +484,9 @@ $(document).ready(function () { }); function topFunction() { - window.scrollBy(0, -100) - scrolldelay = setTimeout('topFunction()', 10) - var sTop = document.documentElement.scrollTop + document.body.scrollTop - if (sTop === 0) { - clearTimeout(scrolldelay) - } + $('body,html').animate({ + scrollTop: 0 + }) } function timeSeriesReload(flag) { diff --git a/style.css b/style.css index 8d844c9..ce049ae 100644 --- a/style.css +++ b/style.css @@ -1709,6 +1709,10 @@ i.iconfont.hotpost { background: #FBFBFB } +body.dark .s-content{ + background: unset; +} + .s-time i { font-size: 13px; margin-right: 5px @@ -5890,6 +5894,11 @@ i.iconfont.down { background-color: #f1f1f1 } +body.dark .user-menu-option a:hover { + color: #3daee9; + background-color: #232629 +} + .no-logged { font-size: 13px; padding: 15px 10px; @@ -5899,7 +5908,7 @@ i.iconfont.down { .no-logged a { display: initial; - color: #69d2e7; + color: #69d2e7 !important; font-size: 14px; padding: 0 5px; text-decoration: underline