1 line
10 KiB
JavaScript
Raw Normal View History

2023-03-21 10:49:35 +08:00
(()=>{window.encrypt=e=>window.btoa(unescape(encodeURIComponent(e))),window.decrypt=e=>decodeURIComponent(escape(window.atob(e)));const t={initWidget(){var e=$(".columns .column-right"),t=$(".columns .column-right-shadow");if($(".widget.recent-comments .reply .link").html((e,t)=>Utils.renderedEmojiHtml(t)),e.length&&t.length&&!t[0].children.length)for(const a of e[0].children)t[0].append(a.cloneNode(!0))},initActions(){const a=$(".actions>.bullet-screen");"true"===localStorage.getItem("stop-bullet-screen")&&a.addClass("stop-bullet-screen"),0!==$("halo-comment[bullet-screen]").length&&a.removeClass("is-hidden-all");a.on("click",()=>{var t,e=localStorage.getItem("stop-bullet-screen")||!1;t="true"!==e.toString(),$("halo-comment[bullet-screen]").each(function(){var e=this.shadowRoot.getElementById("halo-comment");t?$(e).attr("stop-bullet-screen","true"):$(e).removeAttr("stop-bullet-screen")}),t?a.addClass("stop-bullet-screen"):a.removeClass("stop-bullet-screen"),localStorage.setItem("stop-bullet-screen",t)})},initTocAndNotice(){var e=location["pathname"],t=(window.tocPjax&&window.tocPjax(),0===$(".widget.toc .card-content ul").length),e="toc"===DreamConfig.notice_show_mode&&!t||"index"===DreamConfig.notice_show_mode&&"/"!==e;t?$(".widget.toc,.action-toc").addClass("is-hidden-all"):$(".widget.toc,.action-toc").removeClass("is-hidden-all"),e?$(".widget.notice").addClass("is-hidden-all"):$(".widget.notice").removeClass("is-hidden-all")},initBanner(){const o=$(".banner-info-desc");if(0!==o.length){const s=o.text();o.text("");let t,a="",n=!0;const i=function(){var e=a.length;n&&e<s.length?(a+=s.charAt(e),o.text(a)):!n&&0<e?(a=a.slice(0,e-1),o.text(a)):(clearInterval(t),n=!n,t=setInterval(i,n?500:80))};t=setInterval(i,n?500:80)}},initGallery(){$(".main-content img:not(.not-gallery)").each(function(){0===$(this).parents("[data-fancybox],mew-photos").length&&$(this).wrap(`<div class="gallery-item"><div data-fancybox="gallery" ${this.alt?`data-caption="${this.alt}"`:""} href="${$(this).attr("src")}"></div>${this.alt?`<p>${this.alt}</p>`:""}</div>`)})},initMode(){let e=localStorage.getItem("night")||!1;const t=t=>{t?document.documentElement.classList.add("night"):document.documentElement.classList.remove("night"),$("halo-comment").each(function(){var e=this.shadowRoot.getElementById("halo-comment");$(e)[(t?"add":"remove")+"Class"]("night")}),localStorage.setItem("night",t),e=t};$("#toggle-mode").on("click",()=>t("true"!==e.toString())),"system"===DreamConfig.default_theme&&window.matchMedia("(prefers-color-scheme: dark)").addListener(e=>t(e.matches))},initNavbar(){var t=$(".navbar-nav a"),e=$(".panel-side-menu .link");let a=0;var{href:n,pathname:o}=location;if(o&&"/"!==o)for(let e=0;e<t.length;e++){const s=t[e].getAttribute("href");if((o.includes(s)||n.includes(s))&&(a=e,o===s||n===s))break}const s=t.eq(a);s.addClass("current"),s.parents(".item-dropdown").length&&s.parents(".item-dropdown").find(".item-dropdown-link a").addClass("current"),e.eq(a).addClass("current")},initDropMenu(){$(".item-dropdown").each(function(e,t){var a=$(this).find(".item-dropdown-menu"),n=$(t).attr("trigger")||"click",t=$(t).attr("placement")||$(this).height()||0;a.css("top",t),"hover"===n?$(this).hover(()=>$(this).addClass("active"),()=>$(this).removeClass("active")):($(this).on("click",function(e){e.stopPropagation(),$(this).toggleClass("active"),$(document).one("click",()=>$(this).removeClass("active")),e.stopPropagation()}),a.on("click",e=>e.stopPropagation()))})},initScroll(){let o=0;document.addEventListener("scroll",()=>{var e=$(document).scrollTop(),t=(a=(t=e)>o,o=t,a),a=$("body"),n=$(".actions");50<e&&t?a.addClass("move-up"):a.removeClass("move-up"),100<e?n.addClass("show"):n.removeClass("show")})},searchDialog(){const t=$(".navbar-search .result");$(".navbar-search .input").on("click",function(e){e.stopPropagation(),t.addClass("active")}),$(document).on("click",function(){t.removeClass("active")})},drawerMobile(){$(".navbar-slideicon").on("click",function(e){e.stopPropagation(),$(".navbar-searchout").removeClass("active");var e=$("html"),t=$(".navb