diff --git a/templates/assets/js/halo.js b/templates/assets/js/halo.js index 6023c537..3bd26475 100644 --- a/templates/assets/js/halo.js +++ b/templates/assets/js/halo.js @@ -1,16 +1,16 @@ let halo = { - darkComment : ()=>{ - if(document.querySelector('#comment div').shadowRoot.querySelector('.halo-comment-widget').classList != null){ - let commentDOMclass = document.querySelector('#comment div').shadowRoot.querySelector('.halo-comment-widget').classList - if(commentDOMclass.contains('light')) - commentDOMclass.replace('light','dark') + darkComment: () => { + if (document.querySelector('#comment div').shadowRoot.querySelector('.halo-comment-widget').classList != null) { + let commentDOMclass = document.querySelector('#comment div').shadowRoot.querySelector('.halo-comment-widget').classList + if (commentDOMclass.contains('light')) + commentDOMclass.replace('light', 'dark') else - commentDOMclass.replace('dark','light') + commentDOMclass.replace('dark', 'light') } }, - dataCodeTheme : ()=>{ + dataCodeTheme: () => { var t = document.documentElement.getAttribute('data-theme') var e = document.querySelector("link[data-code-theme=light]"), @@ -23,7 +23,7 @@ let halo = { * 代码 * 只适用于halo的代码渲染 */ - addPrismTool : ()=>{ + addPrismTool: () => { if (typeof Prism === 'undefined' || typeof document === 'undefined') { return; } @@ -144,7 +144,7 @@ let halo = { customItem.className = 'custom-item absolute top-0' //复制 - if(isEnableCopy){ + if (isEnableCopy) { var copy = document.createElement("i"); copy.className = 'haofont hao-icon-paste copy-button code-copy cursor-pointer' @@ -181,7 +181,7 @@ let halo = { }; //折叠 - if(isEnableExpander){ + if (isEnableExpander) { var expander = document.createElement("i"); expander.className = 'fa-sharp fa-solid haofont hao-icon-angle-down code-expander cursor-pointer' customItem.appendChild(expander) @@ -189,7 +189,6 @@ let halo = { expander.addEventListener('click', prismToolsFn) - } const expandCode = function () { @@ -214,12 +213,12 @@ let halo = { r.classList.toggle("expand-done-expander"); if (toolbar.classList.contains('c-expander')) { r.firstElementChild.style.display = "none"; - if($nextEle.contains('code-expand-btn')){ + if ($nextEle.contains('code-expand-btn')) { r.offsetParent.lastElementChild.style.display = "none"; } } else { r.firstElementChild.style.display = "block"; - if($nextEle.contains('code-expand-btn') && !r.classList.contains('expand-done')){ + if ($nextEle.contains('code-expand-btn') && !r.classList.contains('expand-done')) { r.offsetParent.lastElementChild.style.display = "block"; } } @@ -247,7 +246,7 @@ let halo = { Prism.hooks.add("complete", r) }, - addScript: (e,t,n)=>{ + addScript: (e, t, n) => { if (document.getElementById(e)) return n ? n() : void 0; let a = document.createElement("script"); @@ -257,7 +256,7 @@ let halo = { document.head.appendChild(a) }, - danmu: ()=>{ + danmu: () => { const e = new EasyDanmakuMin({ el: "#danmu", line: 10, @@ -270,7 +269,7 @@ let halo = { e.batchSend(t, !0); else { let n = []; - if(GLOBAL_CONFIG.source.comments.use == 'Twikoo'){ + if (GLOBAL_CONFIG.source.comments.use == 'Twikoo') { fetch(GLOBAL_CONFIG.source.twikoo.twikooUrl, { method: "POST", body: JSON.stringify({ @@ -282,8 +281,8 @@ let halo = { headers: { "Content-Type": "application/json" } - }).then((e=>e.json())).then((({data: t})=>{ - t.forEach((e=>{ + }).then((e => e.json())).then((({data: t}) => { + t.forEach((e => { null == e.avatar && (e.avatar = "https://cravatar.cn/avatar/d615d5793929e8c7d70eab5f00f7f5f1?d=mp"), n.push({ avatar: e.avatar, @@ -298,7 +297,7 @@ let halo = { } )) } - if(GLOBAL_CONFIG.source.comments.use == 'Artalk'){ + if (GLOBAL_CONFIG.source.comments.use == 'Artalk') { const statheaderList = { method: 'POST', headers: { @@ -308,12 +307,12 @@ let halo = { body: new URLSearchParams({ 'site_name': GLOBAL_CONFIG.source.artalk.siteName, 'limit': '100', - 'type':'latest_comments' + 'type': 'latest_comments' }) } fetch(GLOBAL_CONFIG.source.artalk.artalkUrl + 'api/stat', statheaderList) - .then((e=>e.json())).then((({data: t})=>{ - t.forEach((e=>{ + .then((e => e.json())).then((({data: t}) => { + t.forEach((e => { n.push({ avatar: 'https://cravatar.cn/avatar/' + e.email_encrypted + '?d=mp&s=240', content: e.nick + ":" + btf.changeContent(e.content_marked), @@ -327,12 +326,12 @@ let halo = { } )) } - if(GLOBAL_CONFIG.source.comments.use == 'Waline'){ + if (GLOBAL_CONFIG.source.comments.use == 'Waline') { const loadWaline = () => { Waline.RecentComments({ serverURL: GLOBAL_CONFIG.source.waline.serverURL, count: 50 - }).then(({ comments }) => { + }).then(({comments}) => { const walineArray = comments.map(e => { return { 'content': e.nick + ":" + btf.changeContent(e.comment), @@ -375,10 +374,10 @@ let halo = { }) } - function renderer(values){ + function renderer(values) { var data = getArrayItems(values, 1); let powerStar = document.getElementById("power-star") - if (values.length===0){ + if (values.length === 0) { powerStar.href = GLOBAL_CONFIG.source.power.powerLink powerStar.innerHTML = `
@@ -387,7 +386,7 @@ let halo = {
还没有人赞助~
为爱发电,点击赞助
`; - }else { + } else { if (powerStar) { powerStar.href = "https://afdian.net/u/" + data[0].user_id powerStar.innerHTML = ` @@ -415,7 +414,8 @@ let halo = { } } } - function init(){ + + function init() { const data = saveToLocal.get('power-data') if (data) { renderer(JSON.parse(data)) @@ -423,7 +423,20 @@ let halo = { getPower() } } + document.getElementById("power-star") && init() + }, + + checkAd() { + var default_enable = GLOBAL_CONFIG.source.footer.default_enable + if (default_enable) { + var adElement = document.getElementById("footer-banner"); + if (adElement.offsetWidth <= 0 || adElement.offsetHeight <= 0) { + // 元素不可见,可能被拦截 + console.log("Element may be blocked by AdBlocker Ultimate"); + alert("页脚信息可能被AdBlocker Ultimate拦截,请检查广告拦截插件!") + } + } } diff --git a/templates/assets/zhheo/blogex.js b/templates/assets/zhheo/blogex.js index aba8820f..9242b515 100644 --- a/templates/assets/zhheo/blogex.js +++ b/templates/assets/zhheo/blogex.js @@ -1,5 +1,6 @@ +function checkOpen() { +} -function checkOpen() {} checkOpen.toString = function () { this.opened = true; }; @@ -13,7 +14,7 @@ function coverColor() { // 获取颜色 https://github.com/fast-average-color/fast-average-color const fac = new FastAverageColor(); - fac.getColorAsync(path,{ + fac.getColorAsync(path, { // 忽略白色 ignoredColor: [255, 255, 255, 255] }) @@ -221,7 +222,7 @@ var getTimeState = () => { }, //深色模式切换 - switchDarkMode = ()=>{ + switchDarkMode = () => { "dark" === document.documentElement.getAttribute("data-theme") ? (activateLightMode(), saveToLocal.set("theme", "light", 2), void 0 !== GLOBAL_CONFIG.Snackbar && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day, false, 2000), @@ -232,14 +233,14 @@ var getTimeState = () => { handleCases() heo.darkModeStatus(); //代码块 - if(GLOBAL_CONFIG.prism.enable){ + if (GLOBAL_CONFIG.prism.enable) { halo.dataCodeTheme(); } } - , handleCases = ()=>{ + , handleCases = () => { "function" == typeof utterancesTheme && utterancesTheme(), "object" == typeof FB && window.loadFBComment(), - window.DISQUS && document.getElementById("disqus_thread").children.length && setTimeout((()=>window.disqusReset()), 200) + window.DISQUS && document.getElementById("disqus_thread").children.length && setTimeout((() => window.disqusReset()), 200) } , navFn = { switchDarkMode: switchDarkMode @@ -250,7 +251,7 @@ function rightMenuCommentText(txt) { if (GLOBAL_CONFIG.rightMenuEnable) { rm.hideRightMenu(); } - var input = document.getElementsByClassName(GLOBAL_CONFIG.source.comments.textarea)[0]; + var input = document.getElementsByClassName(GLOBAL_CONFIG.source.comments.textarea)[0]; let evt = document.createEvent('HTMLEvents'); evt.initEvent('input', true, true); let inputValue = replaceAll(txt, '\n', '\n> ') @@ -264,6 +265,7 @@ function rightMenuCommentText(txt) { document.getElementById("comment-tips").classList.add("show"); } } + //替换所有内容 function replaceAll(string, search, replace) { return string.split(search).join(replace); @@ -317,7 +319,8 @@ function travelling() { renderer(json.items); }) } - function renderer(data){ + + function renderer(data) { var linksData = data var name = '' var link = '' @@ -342,7 +345,8 @@ function travelling() { } }); } - function init(){ + + function init() { const data = saveToLocal.get('links-data') if (data) { renderer(JSON.parse(data)) @@ -350,6 +354,7 @@ function travelling() { getLinks() } } + init() } @@ -370,12 +375,12 @@ function toforeverblog() { } //前往开往项目 -function totraveling () { - btf.snackbarShow("即将跳转到「开往」项目的成员博客,不保证跳转网站的安全性和可用性", function(element) { +function totraveling() { + btf.snackbarShow("即将跳转到「开往」项目的成员博客,不保证跳转网站的安全性和可用性", function (element) { element.style.opacity = 0, travellingsTimer && clearTimeout(travellingsTimer) }, 5000, "取消"), - travellingsTimer = setTimeout(function() { + travellingsTimer = setTimeout(function () { window.open("https://www.travellings.cn/go.html", "_blank") }, "5000") } @@ -426,7 +431,7 @@ function getArrayItems(arr, num) { //评论增加放大功能 function owoBig() { - new MutationObserver((e=>{ + new MutationObserver((e => { for (let t of e) if ("childList" === t.type) for (let e of t.addedNodes) @@ -437,10 +442,10 @@ function owoBig() { , a = document.createElement("div"); a.id = "owo-big", document.querySelector("body").appendChild(a), - t.addEventListener("contextmenu", (e=>e.preventDefault())), - t.addEventListener("mouseover", (e=>{ + t.addEventListener("contextmenu", (e => e.preventDefault())), + t.addEventListener("mouseover", (e => { "LI" === e.target.tagName && n && (n = !1, - o = setTimeout((()=>{ + o = setTimeout((() => { let t = 3 * e.target.clientWidth , o = e.x - e.offsetX - (t - e.target.clientWidth) / 2 , n = e.y - e.offsetY; @@ -454,7 +459,7 @@ function owoBig() { ), 300)) } )), - t.addEventListener("mouseout", (e=>{ + t.addEventListener("mouseout", (e => { a.style.display = "none", n = !0, clearTimeout(o) @@ -487,7 +492,7 @@ document.querySelector('#console') && document.querySelector('#console').addEven // }) //自动调整即刻短文尺寸 -window.addEventListener("resize", (function() { +window.addEventListener("resize", (function () { document.querySelector("#waterfall") && heo.reflashEssayWaterFall() } )); @@ -509,8 +514,8 @@ $(".topGroup").hover(function () { function initObserver() { var e = document.getElementById("post-comment") , t = document.getElementById("pagination"); - e && new IntersectionObserver((function(e) { - e.forEach((function(e) { + e && new IntersectionObserver((function (e) { + e.forEach((function (e) { e.isIntersecting ? (t && t.classList.add("show-window"), document.querySelector(".comment-barrage").style.bottom = "-200px") : (t && t.classList.remove("show-window"), document.querySelector(".comment-barrage").style.bottom = "0px") @@ -523,7 +528,8 @@ function initObserver() { // 页面百分比 function percent() { let e = document.documentElement.scrollTop || window.pageYOffset - , t = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight) - document.documentElement.clientHeight + , + t = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight) - document.documentElement.clientHeight , o = Math.round(e / t * 100) , n = document.querySelector("#percent"); var a = window.scrollY + document.documentElement.clientHeight @@ -549,21 +555,22 @@ function checkUrlAndAddHideBanner() { } } -function setBodyDataType(){ +function setBodyDataType() { var body = document.body; var att = document.createAttribute("data-type"); att.value = GLOBAL_CONFIG.htmlType; body.setAttributeNode(att); } + function listenToPageInputPress() { var e = document.getElementById("toPageText") , t = document.getElementById("toPageButton"); - e && (e.addEventListener("keydown", (e=>{ + e && (e.addEventListener("keydown", (e => { 13 === e.keyCode && (heo.toPage(), pjax.loadUrl(t.href)) } )), - e.addEventListener("input", (function() { + e.addEventListener("input", (function () { "" === e.value || "0" === e.value ? t.classList.remove("haveValue") : t.classList.add("haveValue"); var o = document.querySelectorAll(".page-number") , n = +o[o.length - 1].innerHTML; @@ -571,34 +578,36 @@ function listenToPageInputPress() { } ))) } + function initBlog() { // 图片主色 GLOBAL_CONFIG.source.post.dynamicBackground && coverColor(), GLOBAL_CONFIG.rightMenuEnable && addRightMenuClickEvent(), - percent(), - listenToPageInputPress(), - setBodyDataType(), - heo.topPostScroll(), - heo.sayhi(), - heo.stopImgRightDrag(), - heo.addPowerLinksInPostRightSide(), - heo.qrcodeCreate(), - //右下角 snackbar 弹窗 + percent(), + listenToPageInputPress(), + setBodyDataType(), + heo.topPostScroll(), + heo.sayhi(), + heo.stopImgRightDrag(), + heo.addPowerLinksInPostRightSide(), + heo.qrcodeCreate(), + //右下角 snackbar 弹窗 GLOBAL_CONFIG.source.tool.switch && heo.hidecookie(), - heo.onlyHome(), - heo.addNavBackgroundInit(), - heo.initIndexEssay(), - heo.reflashEssayWaterFall(), - heo.darkModeStatus(), - heo.categoriesBarActive(), - heo.initThemeColor(), - heo.topCategoriesBarScroll(), - //隐藏加载动画 - GLOBAL_CONFIG.loadingBox && heo.hideLoading(), - heo.tagPageActive(), - initObserver(), - checkUrlAndAddHideBanner(), - halo.getTopSponsors() + heo.onlyHome(), + heo.addNavBackgroundInit(), + heo.initIndexEssay(), + heo.reflashEssayWaterFall(), + heo.darkModeStatus(), + heo.categoriesBarActive(), + heo.initThemeColor(), + heo.topCategoriesBarScroll(), + //隐藏加载动画 + GLOBAL_CONFIG.loadingBox && heo.hideLoading(), + heo.tagPageActive(), + initObserver(), + checkUrlAndAddHideBanner(), + halo.getTopSponsors(), + halo.checkAd() } @@ -786,11 +795,11 @@ if (getCookie('browsertc') != 1) { //注入函数 document.addEventListener('pjax:click', function () { //显示加载进度条 - if(GLOBAL_CONFIG.loadProgressBar){ + if (GLOBAL_CONFIG.loadProgressBar) { Pace.restart(); } //显示加载动画 - if(GLOBAL_CONFIG.loadingBox){ + if (GLOBAL_CONFIG.loadingBox) { heo.showLoading(); } -}) \ No newline at end of file +}) diff --git a/templates/modules/variables/site-config.html b/templates/modules/variables/site-config.html index 9beb872a..2299da95 100644 --- a/templates/modules/variables/site-config.html +++ b/templates/modules/variables/site-config.html @@ -8,11 +8,14 @@ isHome: [[${ htmlType == 'index'}]], copyright: undefined, lightbox: 'fancybox', - lazyload: {enable: [[${theme.config.other.vanillaLazyload.enable}]], error: [[@{${theme.config.other.vanillaLazyload.errorImg}}]] }, + lazyload: { + enable: [[${theme.config.other.vanillaLazyload.enable}]], + error: [[@{${theme.config.other.vanillaLazyload.errorImg}}]] + }, isFriendLinksInFooter: [[${theme.config.footer.footer_group.enable_footer_group}]], loadingBox: [[${theme.config.other.loadingBoxs.loadingBoxEnable}]], loadProgressBar: [[${theme.config.other.loadingBoxs.loadProgressBar}]], - navMusicEnable:[[${theme.config.tool.nav_music.nav_musicEnable}]], + navMusicEnable: [[${theme.config.tool.nav_music.nav_musicEnable}]], isMusic: [[${ htmlType == 'music'}]], helloText: [[${#strings.listSplit(theme.config.sidebar.profile.helloText, ',')}]], profileStyle: [[${theme.config.sidebar.profile.profileStyle}]], @@ -34,12 +37,12 @@ position: "top-center", }, translate: { - defaultEncoding:[[${theme.config.style.translate.defaultEncoding}]], - translateDelay:0, - msgToTraditionalChinese:"繁", - msgToSimplifiedChinese:"简", - rightMenuMsgToTraditionalChinese:"轉為繁體", - rightMenuMsgToSimplifiedChinese:"转为简体" + defaultEncoding: [[${theme.config.style.translate.defaultEncoding}]], + translateDelay: 0, + msgToTraditionalChinese: "繁", + msgToSimplifiedChinese: "简", + rightMenuMsgToTraditionalChinese: "轉為繁體", + rightMenuMsgToSimplifiedChinese: "转为简体" }, prism: { enable: [[${ theme.config.code.enable }]], @@ -48,15 +51,15 @@ enable_line: [[${ theme.config.code.enable_line }]], enable_copy: [[${ theme.config.code.enable_copy }]], enable_expander: [[${ theme.config.code.enable_expander }]], - prism_limit: Number([[${#strings.isEmpty(theme.config.code.height_limit) ? 300 : theme.config.code.height_limit}]])+30, + prism_limit: Number([[${#strings.isEmpty(theme.config.code.height_limit) ? 300 : theme.config.code.height_limit}]]) + 30, enable_height_limit: [[${theme.config.code.enable_height_limit}]] }, source: { - power:{ + power: { powerLink: [[${theme.config.sidebar.power.powerLink}]], - url:[[${theme.config.sidebar.power.url}]], - userId:[[${theme.config.sidebar.power.userId}]], - showNum:[[${theme.config.sidebar.power.showNum}]] + url: [[${theme.config.sidebar.power.url}]], + userId: [[${theme.config.sidebar.power.userId}]], + showNum: [[${theme.config.sidebar.power.showNum}]] }, links: { linksUrl: [[${ theme.config.link.linksUrl }]], @@ -71,7 +74,7 @@ js: 'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/fancybox/3.5.7/jquery.fancybox.min.js', css: '/null' }, - comments:{ + comments: { use: [[${theme.config.comments.use}]], maxBarrage: [[${ theme.config.comments.commentBarrageConfig.maxBarrage }]], barrageTime: [[${ theme.config.comments.commentBarrageConfig.barrageTime }]], @@ -81,53 +84,54 @@ theme.config.comments.use == 'Artalk' ? 'atk-textarea' : theme.config.comments.use == 'Waline' ? 'wl-editor' : 'appearance-none' }]] }, - welcome:{ - key:"[(${theme.config.sidebar.welcome.key})]", + welcome: { + key: "[(${theme.config.sidebar.welcome.key})]", locationLng: [[${theme.config.sidebar.welcome.locationLng}]], locationLat: [[${theme.config.sidebar.welcome.locationLat}]] }, - post:{ + post: { dynamicBackground: [[${ theme.config.post.dynamicBackground }]] }, - tool:{ + tool: { switch: [[${ theme.config.tool.snackbar.switch }]] }, - postAi:{ - ai : [[${htmlType != 'post' || !theme.config.post.aiDescription.aiDescriptionEnable ? '' : + postAi: { + ai: [[${htmlType != 'post' || !theme.config.post.aiDescription.aiDescriptionEnable ? '' : theme.config.post.aiDescription.mode != 'local' && !theme.config.post.aiDescription.switchBtn ? '' : post.spec.excerpt.autoGenerate ? '本地模式需要自己填写文章摘要' : #strings.isEmpty(post.status.excerpt) ? '请填写文章摘要' : post.status.excerpt }]], - randomNum : [[${theme.config.post.aiDescription.randomNum}]], - basicWordCount : [[${theme.config.post.aiDescription.basicWordCount}]], - btnLink : "[(${theme.config.post.aiDescription.btnLink})]", - gptName : "[(${theme.config.post.aiDescription.gptName})]", - modeName : [[${theme.config.post.aiDescription.mode}]], - switchBtn : [[${theme.config.post.aiDescription.switchBtn}]], - keys : "[(${theme.config.post.aiDescription.key})]", - Referers : "[(${theme.config.post.aiDescription.Referer})]", + randomNum: [[${theme.config.post.aiDescription.randomNum}]], + basicWordCount: [[${theme.config.post.aiDescription.basicWordCount}]], + btnLink: "[(${theme.config.post.aiDescription.btnLink})]", + gptName: "[(${theme.config.post.aiDescription.gptName})]", + modeName: [[${theme.config.post.aiDescription.mode}]], + switchBtn: [[${theme.config.post.aiDescription.switchBtn}]], + keys: "[(${theme.config.post.aiDescription.key})]", + Referers: "[(${theme.config.post.aiDescription.Referer})]", }, - img:{ + img: { src: [[${isLazyload ? 'data-lazy-src' : 'src' }]] }, - twikoo:{ - js:[[${not #strings.isEmpty(theme.config.comments.twikoos.js) ? theme.config.comments.twikoos.js : assets_link +'/libs/twikoo/twikoo.all.min.js' }]], + twikoo: { + js: [[${not #strings.isEmpty(theme.config.comments.twikoos.js) ? theme.config.comments.twikoos.js : assets_link +'/libs/twikoo/twikoo.all.min.js' }]], twikooUrl: "[(${theme.config.comments.twikoos.envId})]", accessToken: "[(${theme.config.comments.twikoos.accessToken})]", - }, - artalk:{ - js:[[${not #strings.isEmpty(theme.config.comments.artalks.artalkJs) ? theme.config.comments.artalks.artalkJs : assets_link +'/libs/artalk/Artalk.js' }]], - css:[[${not #strings.isEmpty(theme.config.comments.artalks.artalkCss) ? theme.config.comments.artalks.artalkCss : assets_link +'/libs/artalk/Artalk.css' }]], + artalk: { + js: [[${not #strings.isEmpty(theme.config.comments.artalks.artalkJs) ? theme.config.comments.artalks.artalkJs : assets_link +'/libs/artalk/Artalk.js' }]], + css: [[${not #strings.isEmpty(theme.config.comments.artalks.artalkCss) ? theme.config.comments.artalks.artalkCss : assets_link +'/libs/artalk/Artalk.css' }]], artalkUrl: "[(${theme.config.comments.artalks.server})]", siteName: "[(${theme.config.comments.artalks.siteName})]", }, - waline:{ - js:[[${not #strings.isEmpty(theme.config.comments.walines.walinesJs) ? theme.config.comments.walines.walinesJs : 'https://cdn.cbd.int/@waline/client@2.15.7/dist/waline.js' }]], + waline: { + js: [[${not #strings.isEmpty(theme.config.comments.walines.walinesJs) ? theme.config.comments.walines.walinesJs : 'https://cdn.cbd.int/@waline/client@2.15.7/dist/waline.js' }]], serverURL: "[(${theme.config.comments.walines.serverURL})]", - locale: [(${not #strings.isEmpty(theme.config.comments.walines.locale) ? theme.config.comments.walines.locale : {} })] - }, - }, - + locale: [[${not #strings.isEmpty(theme.config.comments.walines.locale) ? theme.config.comments.walines.locale : '' }]] + }, + footer: { + default_enable: [[${theme.config.footer.footerContent.default_enable}]] + } + } };