Files
blog-source/usr/themes/HarmonyHues/assets/js/harmonyhues.min.js
2026-03-04 00:23:03 +08:00

1 line
13 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
$(document).ready(function(){function e(e=d.LIGHT){let o=e;e===d.SYSTEM&&(o=t()),$("html").attr("data-theme",o),n("theme",e,7),n("system_theme",o,1)}function t(){return window.matchMedia("(prefers-color-scheme: dark)").matches?d.DARK:d.LIGHT}function n(e,t,n){const o=new Date;o.setTime(o.getTime()+24*n*60*60*1e3),document.cookie=`${e}=${t}; expires=${o.toUTCString()}; path=/`}function o(e){$(".theme-toggle button").removeClass("active"),e.addClass("active")}function s(){const e=i("theme")||d.LIGHT;let t;t=e===d.LIGHT?$('.theme-toggle button[title="浅色模式"]'):e===d.DARK?$('.theme-toggle button[title="深色模式"]'):e===d.SYSTEM?$('.theme-toggle button[title="跟随系统"]'):$('.theme-toggle button[title="浅色模式"]'),o(t)}function i(e){const t=document.cookie.split(";");for(let n of t){const[t,o]=n.trim().split("=");if(t===e)return o}return null}function a(e,t,n){const o="wechat-qrcode"===t?"zdyqr-qrcode":"wechat-qrcode";$(document).on("click",e,function(){const e=$(`.${t}`),s=$(`.${o}`),i=$(".share-box");if(e.length)e.remove();else{s.remove();const e=decodeURIComponent(_ARTICLE_URL),o=`\n <div class="${t} text-center my-4">\n <img src="${b(e)}" \n alt="分享二维码"\n title="${encodeURIComponent(_ARTICLE_NAME)}">\n <div class="mt-2">${n}</div>\n </div>\n `;i.append(o)}})}function c(e,t){return function(){$(this).addClass(e).removeClass(t)}}function r(e,t){$(e).each(function(e){var n=e*t+"s";$(this).css("animation-delay",n)})}const l=(e,t)=>{let n=null;return function(){n||(n=setTimeout(()=>{e.apply(this,arguments),n=null},t))}};$("#nav-backtop").click(function(){return $("html, body").animate({scrollTop:0},200),!1});const d={LIGHT:"light",DARK:"dark",SYSTEM:"system"};$(".theme-toggle").on("click","button",function(){const t=$(this).attr("title");switch(t){case"浅色模式":e(d.LIGHT);break;case"深色模式":e(d.DARK);break;case"跟随系统":e(d.SYSTEM)}o($(this))}),s(),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{e(d.SYSTEM)});const m=()=>{const e=$(window).scrollTop(),t=$(document).height(),n=$(window).height(),o=Math.round(e/(t-n)*100);o>0?($("#nav-backtop").toggleClass("top-to-active",o>=90),$(".back-to-top").show(),$("#nav-backtop>.top-to-text").text(o>=90?"回到顶部":o)):$(".back-to-top").hide()};let p=!1;$("#navbar").hasClass("nav-ui-one")&&(p=!0),toggleNavOnScroll=((e,t,n,o=100)=>{if(p)return;const s=$(e),i=$(this).scrollTop();i>o?s.hasClass(n)&&s.removeClass(n).addClass(t):s.hasClass(t)&&s.removeClass(t).addClass(n)}),m(),toggleNavOnScroll("#navbar","nav-ui-one","nav-ui-two",100),$(window).scroll(function(){l(m(),100),l(toggleNavOnScroll("#navbar","nav-ui-one","nav-ui-two",50),100)});let u=0,v=0,h=!1;$("#menu-line").click(function(e){e.stopPropagation();const t=$("#nav-components");if(t.length)return void f();const n=$("#mobile-nav");n.append('<div id="mobile-nav-bg" class="pop-tool-overlay-bg"></div>');const o=$(".nav-inner > ul").clone();o.find(".sub-menu").addClass("mt-1"),o.find(".sub-menu>ul").addClass("row p-1 ml-2"),o.find(".sub-menu>ul>li").addClass("col-4 p-1"),o.find(".nav-item").addClass("pb-3"),o.find(".nav-item>.nav-a").addClass("font-weight-bold"),o.find(".nav-item>.nav-a").prepend('<i class="iconfont icon-xingqiu font-weight-normal mr-1"></i>'),n.append(`<div id="nav-components" class="mobile-aside px-3 py-2"><div class="mx-auto"><i class="back-box mb-2"></i></div><div id="mobile-close-btn" class="mobile-close-btn m-2"><i class="iconfont icon-guanbi"></i></div>${o.prop("outerHTML")}</div>`),requestAnimationFrame(()=>{$("#mobile-nav-bg").css({opacity:"1",visibility:"visible",transform:"rotate(0) scale(1)"}),$("#nav-components").addClass("open")}),$("body").css("overflow","hidden")}),$(document).click(function(e){!$("#nav-components").hasClass("open")||$(e.target).closest("#nav-components").length||$(e.target).closest("#menu-line").length||f()}),$("#nav-components").click(function(e){e.stopPropagation()}),$(document).on("touchstart",function(e){$("#nav-components").hasClass("open")&&(u=e.originalEvent.touches[0].pageY,v=u,h=!0)}),$(document).on("touchmove",function(e){if(h){v=e.originalEvent.touches[0].pageY;const t=v-u;t>0&&$("#nav-components").css("transform",`translateY(${t}px)`)}}),$(document).on("touchend",function(){if(h){const e=v-u,t=$("#nav-components").height()/2;e>t?f():$("#nav-components").css("transform",""),h=!1}}),$(document).on("click","#mobile-close-btn",function(){f()});const f=()=>{const e=$("#nav-components"),t=$("#mobile-nav-bg");e.removeClass("open"),t.css({opacity:0,visibility:"hidden"}),e.one("transitionend",function(){e.remove(),t.remove(),$("body").css("overflow","")})};$("#search-btn").click(function(){$(".main-search").addClass("open"),$("body").css("overflow","hidden")}),$(".search-box").on("click","#search-close-btn",function(){$(".main-search").removeClass("open"),$("body").css("overflow","")});const b=(e,t=200)=>{const n=document.createElement("div");$(n).qrcode({text:e,width:t,height:t});const o=n.querySelector("canvas");if(!o)return console.error("二维码生成失败未创建canvas元素"),null;try{return o.toDataURL("image/png")}catch(e){return console.error("Base64转换失败",e),null}},g=(e,t,n)=>$('<div class="main-'+e+'"><div class="pop-tool-overlay-bg"></div><div class="card p-2 p-md-4 pop-tool-box '+e+'-box no-animation">'+t+("poster"==e?"":'<div id="'+n+'" class="close-btn"><i class="iconfont icon-guanbi"></i></div>')+"</div></div>"),w=(e,t)=>{0===$(e).length&&$("body").append(t()),requestAnimationFrame(()=>{$(e).addClass("open"),$("body").css("overflow","hidden")})},y=e=>{e.removeClass("open"),$("body").css("overflow",""),setTimeout(function(){e.remove()},500)};$(document).on("click",".close-btn,.pop-close-btn",function(){const e=$(this).closest(".main-poster, .main-reward, .main-share");y(e)}),$(document).click(function(e){const t=$(e.target);!t.closest(".search-box, #search-btn").length&&$(".search-box").is(":visible")&&($(".main-search").removeClass("open"),$("body").css("overflow","")),!t.closest(".poster-box, #poster-btn, .down-btn-box").length&&$(".poster-box").is(":visible")&&y($(".main-poster")),!t.closest(".reward-box, #reward-btn").length&&$(".reward-box").is(":visible")&&y($(".main-reward")),!t.closest(".share-box, #share-btn").length&&$(".share-box").is(":visible")&&y($(".main-share"))}),$(document).click(function(e){e.stopPropagation()});const C=()=>{var e=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],t=new Date,n=t.getDate();const o=n<10?"0"+n:n,s=t.getDay(),i=$("#logo>img").attr("src"),a=$(".author-left>name>a").first().text(),c=$(".post-category > a").first().text();return g("poster",`<div id="posterCapture" class="poster-post-box p-3">\n <div class="poster-cover"><img src="${decodeURIComponent(_ARTICLE_COVER_URL)}" /></div>\n <div class="poster-content d-flex flex-row align-items-start mt-4">\n <div class="poster-date text-center px-2 py-1 flex-shrink-0">\n <div style="font-size: 1rem;color:red;">${e[s]}</div>\n <div class="font-weight-bold" style="font-size:1.5rem;">${o}</div>\n </div>\n <div class="poster-post-content flex-grow-1">\n <h5 class="poster-post-title font-weight-bold">${decodeURIComponent(_ARTICLE_NAME)}</h5>\n <p class="poster-post-text m-0">作者:${a}&nbsp;|&nbsp;分类:${c}</p>\n </div>\n </div>\n <div class="poster-footer d-flex flex-row justify-content-between align-items-center p-2 mt-4" style="color:var(--poster-text-color);">\n <div class="poster-footer-left">\n <div><img style="width:auto;height:25px;" src="${i}">&nbsp;|&nbsp;文章海报</div>\n <div style="font-size:0.9rem;">扫码识别前往查看更多内容👉</div>\n </div>\n <div class="poster-footer-right flex-shrink-0">\n <img style="height:50px;" src="${b(decodeURIComponent(_ARTICLE_URL))}">\n </div>\n </div>\n </div>\n <div class="down-btn-box">\n <div class="post-tools d-flex justify-content-center">\n <div class="post-tools-item"><button class="btn" id="poster-download-btn" title="保存海报"><i class="iconfont icon-baocun"></i></button></div>\n <div class="post-tools-item"><button class="btn pop-close-btn" id="poster-close-btn" title="关闭海报"><i class="iconfont icon-guanbi"></i></button></div>\n </div>\n </div>\n `,"poster-close-btn")};$("#poster-btn").click(function(){w(".main-poster",C)}),$(document).on("click","#poster-download-btn",function(){htmlToImage.toPng(document.querySelector("#posterCapture")).then(function(e){var t=document.createElement("a");t.download=decodeURIComponent(_ARTICLE_NAME)+"-海报图片.png",t.href=e,t.click()})});const x=()=>g("reward",'<div class="reward-content d-flex justify-content-center"><div class="reward-qr d-flex flex-column align-items-center"><img src="'+decodeURIComponent(_WXQR)+'" atl="微信支付" /><span>微信</span></div><div class="reward-qr d-flex flex-column align-items-center"><img src="'+decodeURIComponent(_ZFBQR)+'" atl="支付宝支付" /><span>支付宝</span></div></div>',"reward-close-btn");$("#reward-btn").click(function(){w(".main-reward",x)});const R={qq:"http://connect.qq.com/widget/shareqq/index.html?url=",weibo:"http://service.weibo.com/share/share.php?url=",twitter:"https://twitter.com/intent/tweet?url=",wechat:"javascript:void(0);"},I=()=>g("share",'<p class="p-2">'+decodeURIComponent(_ARTICLE_URL)+'</p><div class="share-a d-flex flex-row justify-content-center"><a class="share-item d-flex align-items-center justify-content-center" href="'+R.qq+decodeURIComponent(_ARTICLE_URL)+"&title="+decodeURIComponent(_ARTICLE_NAME)+'" title="QQ分享"><i class="iconfont icon-qq"></i></a><a class="share-item d-flex align-items-center justify-content-center" href="'+R.weibo+decodeURIComponent(_ARTICLE_URL)+"&title="+decodeURIComponent(_ARTICLE_NAME)+'" title="微博分享"><i class="iconfont icon-weibo"></i></a><a class="share-item d-flex align-items-center justify-content-center" href="'+R.twitter+decodeURIComponent(_ARTICLE_URL)+"&text="+decodeURIComponent(_ARTICLE_NAME)+'" title="推特分享"><i class="iconfont icon-tuite"></i></a><a id="share-wechat" class="share-item d-flex align-items-center justify-content-center" href="'+R.wechat+'" title="朋友圈分享"><i class="iconfont icon-pengyouquan"></i></a><a id="share-zdyqr" class="share-item d-flex align-items-center justify-content-center" href="'+R.wechat+'" title="生成二维码"><i class="iconfont icon-erweima"></i></a></div>',"share-close-btn");$("#share-btn").click(function(){w(".main-share",I)}),a("#share-wechat","wechat-qrcode","微信扫码分享"),a("#share-zdyqr","zdyqr-qrcode","扫码分享");const k=e=>{const t=$.extend({duration:1500,easing:e=>e*(2-e),format:e=>e.toLocaleString()},e),n=$(t.selector);if(!n.length)return void console.error("元素未找到:",t.selector);let o=null;const s=t.end-t.start,i=Math.abs(s)>1e4,a=e=>{o=o||e;const c=e-o,r=Math.min(c/t.duration,1),l=t.easing(r);let d=t.start+s*l;if(i){const e=t.end-d;d=Math.abs(e)>1e3?t.end-e*(1+Math.random()/3):d}n.text(t.format(Math.floor(d))),r<1?requestAnimationFrame(a):n.text(t.format(t.end))};requestAnimationFrame(a)};var T={effect:"fadeIn",threshold:200,container:window,failure_limit:30};$("img.lazy").lazyload($.extend({},T,{load:c("loaded","lazy")})),$(".hh-widget img.widget-lazy").lazyload($.extend({},T,{load:c("loaded","widget-lazy")}));let L=0;const A=$("#navbar"),_=$(".sidebar-sticky"),q=100;if($(window).scroll(function(){const e=$(this).scrollTop();if(e<q)return A.removeClass("nav-hidden").addClass("nav-visible"),void(L=e);Math.abs(e-L)>5&&(e>L?(A.removeClass("nav-visible").addClass("nav-hidden"),_.addClass("visible-top")):(A.removeClass("nav-hidden").addClass("nav-visible"),_.removeClass("visible-top"))),L=e}),r(".nav-menu>.nav-item",.15),r(".hh-widget:not(.no-animation)",.3),r(".card:not(.no-animation)",.3),r(".links-card",.3),"undefined"!=typeof Swiper){var E=new Swiper(".swiper-container",{direction:"horizontal",loop:!0,autoplay:5e3,speed:1e3,autoplayDisableOnInteraction:!1,pagination:".swiper-pagination",paginationClickable:!0,prevButton:".swiper-button-prev",nextButton:".swiper-button-next",roundLengths:!0,parallax:!0,lazyLoading:!0});$(".swiper-container").mouseenter(function(){E.stopAutoplay()}).mouseleave(function(){E.startAutoplay()}),$(".swiper-container").hover(function(){E.stopAutoplay()},function(){E.startAutoplay()})}if("undefined"!=typeof ViewImage&&window.ViewImage&&ViewImage.init(".post-content img[show-img],.comment-list img"),showSvg(),$(".timejourney-progress").length>0){var U=$(".timejourney-progress").data("percentage");const e=U||0;$(".timejourney-progress").css({width:e+"%",transition:"width "+(e/10+1)+"s ease-in-out"}),k({start:0,end:e,duration:e/10*1e3+1500,selector:"#timejourney-progress",format:e=>`${e}%`})}});