优化黑白切换

This commit is contained in:
1152958806@qq.com 2023-10-10 22:34:56 +08:00
parent 0281dd6c48
commit 19682abdaf
2 changed files with 57 additions and 136 deletions

View File

@ -194,22 +194,6 @@ document.addEventListener('DOMContentLoaded', function () {
newEle.addEventListener('click', clickFn) newEle.addEventListener('click', clickFn)
}, },
switchDarkMode: () => { // Switch Between Light And Dark Mode
const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
if (nowMode === 'light') {
activateDarkMode()
saveToLocal.set('theme', 'dark', 2);
GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night,false,2000);
} else {
activateLightMode();
saveToLocal.set('theme', 'light', 2);
GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day,false,2000);
}
// handle some cases
typeof utterancesTheme === 'function' && utterancesTheme()
typeof FB === 'object' && window.loadFBComment()
window.DISQUS && document.getElementById('disqus_thread').children.length && setTimeout(() => window.disqusReset(), 200)
},
showOrHideBtn: () => { // rightside 點擊設置 按鈕 展開 showOrHideBtn: () => { // rightside 點擊設置 按鈕 展開
document.getElementById('rightside-config-hide').classList.toggle('show') document.getElementById('rightside-config-hide').classList.toggle('show')
}, },
@ -249,7 +233,7 @@ document.addEventListener('DOMContentLoaded', function () {
rightSideFn.switchReadMode() rightSideFn.switchReadMode()
break break
case 'darkmode': case 'darkmode':
rightSideFn.switchDarkMode() navFn.switchDarkMode();
break break
case 'hide-aside-btn': case 'hide-aside-btn':
rightSideFn.hideAsideBtn() rightSideFn.hideAsideBtn()

View File

@ -207,8 +207,6 @@ var getTimeState = () => {
} else if (hours > 18 && hours <= 24) { } else if (hours > 18 && hours <= 24) {
text = `晚上好`; text = `晚上好`;
} }
//    console.log(`hours >>>>>`, hours);
//    console.log(`text >>>>`, text);
// 返回当前时间段对应的状态 // 返回当前时间段对应的状态
return text; return text;
@ -221,72 +219,31 @@ var getTimeState = () => {
t t
} }
}; },
function fly_to_top() {
document.getElementById("guli_top").classList.add("open_wing");
setTimeout(function () {
document.getElementById("guli_top").classList.add("flying");
btf.scrollToDest(0, 300);
}, 300);
setTimeout(function () {
// 这里就是处理的事件
document.getElementById("guli_top").classList.remove("flying");
document.getElementById("guli_top").classList.remove("open_wing");
document.getElementById("guli_top").style.cssText = "opacity: ''; transform: ''";
}, 600)
}
//深色模式切换 //深色模式切换
var navFn = { switchDarkMode = ()=>{
switchDarkMode: () => { // Switch Between Light And Dark Mode "dark" === document.documentElement.getAttribute("data-theme") ? (activateLightMode(),
const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light' saveToLocal.set("theme", "light", 2),
if (nowMode === 'light') { void 0 !== GLOBAL_CONFIG.Snackbar && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day, false, 2000),
activateDarkMode() $(".menu-darkmode-text").text("深色模式")) : (activateDarkMode(),
saveToLocal.set('theme', 'dark', 2) saveToLocal.set("theme", "dark", 2),
GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night, false, 2000) void 0 !== GLOBAL_CONFIG.Snackbar && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night, false, 2000),
} else { $(".menu-darkmode-text").text("浅色模式")),
activateLightMode() handleCases()
saveToLocal.set('theme', 'light', 2)
GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day, false, 2000)
}
// handle some cases
typeof utterancesTheme === 'function' && utterancesTheme();
typeof FB === 'object' && window.loadFBComment();
window.DISQUS && document.getElementById('disqus_thread').children.length && setTimeout(() => window.disqusReset(), 200)
//统计图
let color = document.documentElement.getAttribute('data-theme') === 'light' ? '#363636' : '#F7F7FA'
if (document.getElementById('posts-chart')) {
let postsOptionNew = postsOption
postsOptionNew.textStyle.color = color
postsOptionNew.title.textStyle.color = color
postsOptionNew.xAxis.axisLine.lineStyle.color = color
postsOptionNew.yAxis.axisLine.lineStyle.color = color
postsChart.setOption(postsOptionNew)
}
if (document.getElementById('tags-chart')) {
let tagsOptionNew = tagsOption
tagsOptionNew.textStyle.color = color
tagsOptionNew.title.textStyle.color = color
tagsOptionNew.xAxis.axisLine.lineStyle.color = color
tagsOptionNew.yAxis.axisLine.lineStyle.color = color
tagsChart.setOption(tagsOptionNew)
}
if (document.getElementById('categories-chart')) {
let categoriesOptionNew = categoriesOption
categoriesOptionNew.textStyle.color = color
categoriesOptionNew.title.textStyle.color = color
categoriesOptionNew.legend.textStyle.color = color
categoriesChart.setOption(categoriesOptionNew)
}
heo.darkModeStatus(); heo.darkModeStatus();
//代码块 //代码块
if(GLOBAL_CONFIG.prism.enable){ if(GLOBAL_CONFIG.prism.enable){
halo.dataCodeTheme(); halo.dataCodeTheme();
} }
} }
, handleCases = ()=>{
"function" == typeof utterancesTheme && utterancesTheme(),
"object" == typeof FB && window.loadFBComment(),
window.DISQUS && document.getElementById("disqus_thread").children.length && setTimeout((()=>window.disqusReset()), 200)
} }
, navFn = {
switchDarkMode: switchDarkMode
};
//引用到评论 //引用到评论
function rightMenuCommentText(txt) { function rightMenuCommentText(txt) {
@ -326,8 +283,6 @@ function AddRewardMask() {
document.getElementById("quit-box").style.display = "flex"; document.getElementById("quit-box").style.display = "flex";
} }
//监听蒙版关闭 //监听蒙版关闭
document.addEventListener('touchstart', e => { document.addEventListener('touchstart', e => {
RemoveRewardMask() RemoveRewardMask()
@ -346,20 +301,6 @@ $(document).unbind('keydown').bind('keydown', function (e) {
} }
}) })
//判断国内国外
// var foreignTips = (function () {
// var fetchUrl = "https://api.ooomn.com/api/ip"
// fetch(fetchUrl)
// .then(res => res.json())
// .then(json =>{
// var country = json.country;
// console.log(country);
// if (country != '中国'){
// btf.snackbarShow('使用国外网络访问可能无法访问文章图片敬请谅解。Blog pictures only serve mainland China.')
// }
// })
// });
//颜色 //颜色
document.addEventListener('scroll', btf.throttle(function () { document.addEventListener('scroll', btf.throttle(function () {
heo.initThemeColor() heo.initThemeColor()
@ -635,25 +576,28 @@ function initBlog() {
GLOBAL_CONFIG.source.post.dynamicBackground && coverColor(), GLOBAL_CONFIG.source.post.dynamicBackground && coverColor(),
GLOBAL_CONFIG.rightMenuEnable && addRightMenuClickEvent(), GLOBAL_CONFIG.rightMenuEnable && addRightMenuClickEvent(),
percent(), percent(),
heo.topCategoriesBarScroll(),
heo.initIndexEssay(),
setBodyDataType(),
listenToPageInputPress(), listenToPageInputPress(),
setBodyDataType(),
heo.topPostScroll(), heo.topPostScroll(),
heo.sayhi(), heo.sayhi(),
heo.stopImgRightDrag(),
heo.addPowerLinksInPostRightSide(),
heo.qrcodeCreate(), heo.qrcodeCreate(),
//右下角 snackbar 弹窗 //右下角 snackbar 弹窗
GLOBAL_CONFIG.source.tool.switch && heo.hidecookie(), GLOBAL_CONFIG.source.tool.switch && heo.hidecookie(),
heo.stopImgRightDrag(),
heo.addPowerLinksInPostRightSide(),
heo.onlyHome(), heo.onlyHome(),
heo.addNavBackgroundInit(), heo.addNavBackgroundInit(),
heo.initIndexEssay(),
heo.reflashEssayWaterFall(),
heo.darkModeStatus(), heo.darkModeStatus(),
heo.initThemeColor(), heo.initThemeColor(),
heo.topCategoriesBarScroll(),
//隐藏加载动画 //隐藏加载动画
GLOBAL_CONFIG.loadingBox && heo.hideLoading(), GLOBAL_CONFIG.loadingBox && heo.hideLoading(),
initObserver(), initObserver(),
checkUrlAndAddHideBanner() checkUrlAndAddHideBanner()
} }
// 如果当前页有评论就执行函数 // 如果当前页有评论就执行函数
@ -837,8 +781,7 @@ if (getCookie('browsertc') != 1) {
// }; // };
//注入函数 //注入函数
document.addEventListener('pjax:send', function () { document.addEventListener('pjax:click', function () {
//显示加载进度条 //显示加载进度条
if(GLOBAL_CONFIG.loadProgressBar){ if(GLOBAL_CONFIG.loadProgressBar){
Pace.restart(); Pace.restart();
@ -847,10 +790,4 @@ document.addEventListener('pjax:send', function () {
if(GLOBAL_CONFIG.loadingBox){ if(GLOBAL_CONFIG.loadingBox){
heo.showLoading(); heo.showLoading();
} }
})
document.addEventListener('DOMContentLoaded', function () {
heo.reflashEssayWaterFall()
}) })