UNPKG

halo-theme-dream2.0-plus

Version:

梦之城,童话梦境,动漫类型博客主题。

15 lines 12.8 kB
(()=>{class e extends HTMLElement{constructor(){super(),this.hasAttribute("draw")||this.init()}drawComplete(){this.setAttribute("draw",!0)}}document.addEventListener("DOMContentLoaded",()=>{customElements.define("mew-hide",class extends e{init(){var t=$(this),e=t.closest(".main-content");this.options={target:e.attr("data-target"),id:e.attr("data-id")},this.options.target&&this.options.id&&((e=(e=localStorage.getItem(window.encrypt("mew-hide-"+this.options.target)))?JSON.parse(window.decrypt(e)):[]).includes(this.options.id)?(t.before(this.innerHTML),t.remove()):(e=0!==t.find("h1,h2,h3,h4,h5").length,this.setAttribute("hide",window.encrypt(this.innerHTML)),this.innerHTML="",e&&(this.setAttribute("toc",!0),commonContext.initTocAndNotice()),this.onclick=function(){var t=$(`halo-comment[id='${this.options.id}'][type='${this.options.target.substring(0,this.options.target.length-1)}']`);0===t.length||t.is(":hidden")||Utils.animateScroll(t[0],20,(window.innerHeight||document.documentElement.clientHeight)/4)})),this.drawComplete()}}),customElements.define("mew-subtitle",class extends e{init(){this.innerHTML=`<span>${this.innerText||DreamConfig.mew_subtitle_default_title}</span>`,this.drawComplete()}}),customElements.define("mew-music",class e extends HTMLElement{constructor(){super(),this.innerHTML=this.getAttribute("prompt")||"Loading",this.options={container:this,fixed:this.hasAttribute("fixed")||!1,mutex:this.hasAttribute("mutex")||!0,theme:this.getAttribute("theme")||"var(--theme)",loop:this.getAttribute("loop")||"all",autoplay:this.hasAttribute("autoplay")&&"false"!==this.getAttribute("autoplay"),lrcType:this.getAttribute("lrcType")||3,listFolded:this.getAttribute("listFolded")||!1,volume:this.getAttribute("volume")||.7,listMaxHeight:this.getAttribute("listMaxHeight")||"450px",mini:this.getAttribute("mini")||!1,order:this.getAttribute("order")||"list",storageName:this.getAttribute("storageName")||"aplayer-setting"},"APlayer"in window?this.render():e.prototype.load?e.prototype.await.push(()=>this.render()):(e.prototype.load=!0,e.prototype.await=[],new Promise(t=>{$("head").append('<link rel="stylesheet" href="/themes/theme-dream2-plus/assets/lib/aplayer@1.10.1/APlayer.min.css">'),Utils.cachedScript("/themes/theme-dream2-plus/assets/lib/aplayer@1.10.1/APlayer.min.js").done(()=>t()).fail(()=>t())}).then(()=>{this.render(),e.prototype.await&&e.prototype.await.forEach(t=>t())}))}render(){"APlayer"in window?new Promise(async t=>{if(this.hasAttribute("meetingUrl"))this.options.audio=await fetch(this.getAttribute("meetingUrl")).then(t=>t.json());else if(this.hasAttribute("song"))this.options.audio=await fetch("https://api.i-meto.com/meting/api?server=netease&type=song&id="+this.getAttribute("song")).then(t=>t.json());else if(this.hasAttribute("playlist"))this.options.audio=await fetch("https://api.i-meto.com/meting/api?server=netease&type=playlist&id="+this.getAttribute("playlist")).then(t=>t.json());else if(this.hasAttribute("url"))this.options.audio=[{name:this.getAttribute("name")||DreamConfig.mew_music_default_name,url:this.getAttribute("url"),artist:this.getAttribute("artist")||DreamConfig.mew_music_default_artist,cover:this.getAttribute("cover"),lrc:this.getAttribute("lrc")||(this.options.lrcType=void 0)}];else{if(!this.hasAttribute("music-list"))return this.innerHTML=DreamConfig.mew_music_not_music_tip,t();var e=JSON.parse(this.getAttribute("music-list"));e.forEach(t=>{t.lrc=t.lrc||"",t.name=t.name||DreamConfig.mew_music_default_name,t.artist=t.artist||DreamConfig.mew_music_default_artist,t.cover=t.cover||"/themes/theme-dream2-plus/assets/img/music.webp"}),this.options.audio=e}this.aplayer=new APlayer(this.options),t()}).catch(t=>{}):this.innerHTML=DreamConfig.mew_music_not_enabled_tip}getAPlayer(){return this.aplayer}disconnectedCallback(){this.aplayer&&this.aplayer.destroy()}}),customElements.define("mew-bilibili",class extends e{init(){this.options={bvid:this.getAttribute("bvid"),width:/^\d{1,3}%$/.test(this.getAttribute("width"))?this.getAttribute("width"):"100%"},this.options.bvid?(this.style.padding=`calc(${this.options.width} * 0.3) 0`,this.innerHTML=`<iframe allowfullscreen="true" src="//player.bilibili.com/player.html?bvid=${this.options.bvid}&page=1" style="width: ${this.options.width};"></iframe>`):this.innerHTML=DreamConfig.mew_bilibili_not_bvid_tip,this.drawComplete()}}),customElements.define("mew-tabs",class extends e{init(){var t=$(this).children("mew-tab-page");if(0===t.length)this.innerHTML=DreamConfig.mew_tabs_not_tab_tip;else{let s="",o="",a=!1;t.each((t,e)=>{var i=e.getAttribute("title")||DreamConfig.mew_tabs_default_title,t=t+"-"+(new Date).getTime();!a&&e.hasAttribute("active")?(a=!0,s+=`<div class="active" data-id="#${t}">${i}</div>`,o+=`<div class="active" id="${t}">${e.innerHTML}</div>`):(s+=`<div data-id="#${t}">${i}</div>`,o+=`<div id="${t}">${e.innerHTML}</div>`)}),this.innerHTML=`<div class="tabs-head">${s}</div><div class="tabs-body">${o}</div>`,a||$(this).find("div>div:first-child").addClass("active")}this.drawComplete()}connectedCallback(){$(this).find(".tabs-head").on("click","div:not(.active)",function(){var t=$(this).parent().parent();t.find(".active").removeClass("active"),$(this).addClass("active"),t.find($(this).attr("data-id")).addClass("active")})}}),customElements.define("mew-cloud",class extends e{init(){this.options={type:this.getAttribute("type")||"default",title:this.innerText||DreamConfig.mew_cloud_title,url:this.getAttribute("url"),password:this.getAttribute("password")};var t={default:DreamConfig.mew_cloud_default_name,360:DreamConfig.mew_cloud_360_name,115:DreamConfig.mew_cloud_115_name,123:DreamConfig.mew_cloud_123_name,kk:DreamConfig.mew_cloud_kk_name,xl:DreamConfig.mew_cloud_xl_name,onedrive:DreamConfig.mew_cloud_onedrive_name,yd:DreamConfig.mew_cloud_yd_name,ty:DreamConfig.mew_cloud_ty_name,lt:DreamConfig.mew_cloud_lt_name,uc:DreamConfig.mew_cloud_uc_name,pan:DreamConfig.mew_cloud_pan_name,oss:DreamConfig.mew_cloud_oss_name,bd:DreamConfig.mew_cloud_bd_name,wy:DreamConfig.mew_cloud_wy_name,ali:DreamConfig.mew_cloud_ali_name,github:DreamConfig.mew_cloud_github_name,gitee:DreamConfig.mew_cloud_gitee_name,gitlab:DreamConfig.mew_cloud_gitlab_name,gitea:DreamConfig.mew_cloud_gitea_name,git:DreamConfig.mew_cloud_git_name,lz:DreamConfig.mew_cloud_lz_name};this.innerHTML=` <div class="mew-cloud-logo type-${t[this.options.type]?this.options.type:"default"}"></div> <div class="mew-cloud-desc"> <div class="mew-cloud-desc-title">${this.options.title}</div> <div class="mew-cloud-desc-type">${DreamConfig.mew_cloud_source+(t[this.options.type]||DreamConfig.mew_cloud_default_name)}${this.options.password?" | "+DreamConfig.mew_cloud_extraction+this.options.password:""}</div> </div> <a class="mew-cloud-link" href="${this.options.url}" target="_blank" aria-label="${this.options.title}" title="${this.options.title}" rel="noopener noreferrer nofollow"> <i class="ri-download-line"></i> </a> `,this.drawComplete()}}),customElements.define("mew-progress",class extends e{init(){this.options={value:/^\d{1,3}%$/.test(this.getAttribute("value"))?this.getAttribute("value"):"50%",color:this.getAttribute("color")||"var(--theme)"},this.innerHTML=`<div class="mew-progress-bar"> <div class="mew-progress-bar-inner" style="width: ${this.options.value}; background: ${this.options.color};"></div> </div> <div class="mew-progress-value">${this.options.value}</div>`,this.drawComplete()}}),customElements.define("mew-panel",class extends e{init(){this.options={title:this.getAttribute("title")||"",color:this.getAttribute("color")||"var(--theme)"},this.innerHTML=` <div class="mew-panel-title">${this.options.title}</div> <div class="mew-panel-body">${this.innerHTML}</div>`,this.style.background=this.options.color,this.style.color=this.options.color,this.drawComplete()}}),customElements.define("mew-message",class extends e{init(){this.options={type:/^(success|info|warning|error)$/.test(this.getAttribute("type"))?this.getAttribute("type"):"info",content:this.innerHTML||""},this.innerHTML=this.options.content,this.setAttribute("type",this.options.type),this.drawComplete()}}),customElements.define("mew-hr",class extends e{init(){this.startColor=this.getAttribute("startColor")||"#01d0ff",this.endColor=this.getAttribute("endColor")||"#fc3e85",this.style.backgroundImage=`repeating-linear-gradient(-45deg, ${this.startColor} 0,${this.startColor} 20%, transparent 0,transparent 35%, ${this.endColor} 0,${this.endColor} 65%, transparent 0,transparent 80%, ${this.startColor} 0,${this.startColor} 100%)`,this.drawComplete()}}),customElements.define("mew-timeline",class extends e{init(){let t="",e=this.firstChild;for(;e;){var i;"MEW-TIMELINE-TITLE"===e.tagName?t+=`<div class="mew-timeline-title ${e.getAttribute("type")||""}"><span class="mew-timeline-title-elem">${e.innerHTML}</span></div>`:"MEW-TIMELINE-ITEM"===e.tagName&&(e.getAttribute("type"),i=e.getAttribute("title")?`<span class="mew-timeline-item-title">${e.getAttribute("title")}</span>`:"",t+=`<div class="mew-timeline-item ${e.getAttribute("type")||""}">${i}<div class="mew-timeline-item-content">${e.innerHTML}</div></div>`),e=e.nextElementSibling}this.innerHTML=t,this.drawComplete()}}),customElements.define("mew-btn",class extends e{init(){this.options={color:this.getAttribute("color")||"var(--theme)",href:this.getAttribute("href"),target:this.getAttribute("target")||"_blank",icon:this.getAttribute("icon")},this.innerHTML=`<a class="mew-btn" aria-label="${this.options.href}">${this.options.icon?`<i class="${this.options.icon}"></i>`:""}${this.innerHTML}</a>`;var t=this.querySelector("a.mew-btn");this.options.href&&(t.href=this.options.href,t.target=this.options.target),this.drawComplete()}}),customElements.define("mew-quote",class extends e{init(){this.options={avatar:this.getAttribute("avatar"),href:this.getAttribute("href"),name:this.getAttribute("name")};var t=this.options.avatar?`<a class="mew-quote-href" aria-label="${this.options.name}" title="${this.options.name}" target="_blank" ${this.options.href?`href="${this.options.href}"`:""}><img class="quote-avatar-hexagon not-gallery" src="${this.options.avatar}"/></a>`:"",e=this.options.name?`<a class="mew-quote-name" aria-label="${this.options.name}" title="${this.options.name}" target="_blank" ${this.options.href?`href="${this.options.href}"`:""}>${this.options.name}</a>`:"";this.innerHTML=`<div class="mew-quote"><div class="quote-container">${t}<div class="mew-quote-info"><p class="mew-quote-content">${this.innerHTML}</p>${e}</div></div></div>`,this.drawComplete()}}),customElements.define("mew-video",class extends e{init(){this.options={src:this.getAttribute("src"),type:this.getAttribute("type"),autoplay:this.hasAttribute("autoplay")&&"false"!==this.getAttribute("autoplay"),controls:"false"!==this.getAttribute("controls"),loop:this.hasAttribute("loop")&&"false"!==this.getAttribute("loop"),muted:this.hasAttribute("muted")&&"false"!==this.getAttribute("muted"),preload:this.hasAttribute("preload")&&"false"!==this.getAttribute("preload"),poster:this.getAttribute("poster"),width:/^\d{1,3}%$/.test(this.getAttribute("width"))?this.getAttribute("width"):"100%"},this.innerHTML=`<video width="${this.options.width}" ${this.options.poster?`poster="${this.options.poster}"`:""}${this.options.autoplay?" autoplay":""}${this.options.controls?" controls":""}${this.options.loop?" loop":""}${this.options.muted?" muted":""}${this.options.preload?" preload":""}><source src="${this.options.src}" ${this.options.type?`type="${this.options.type}"`:""}>${DreamConfig.global_browser_not_supported}</video>`,this.drawComplete()}}),customElements.define("mew-photos",class t extends e{init(){$.fn.justifiedGallery?this.render():t.prototype.load?t.prototype.await.push(()=>this.render()):(t.prototype.load=!0,t.prototype.await=[],new Promise(t=>{Utils.cachedScript("/themes/theme-dream2-plus/assets/lib/justifiedGallery@3.8.1/jquery.justifiedGallery.min.js").done(()=>t()).fail(()=>t())}).then(()=>{this.render(),t.prototype.await&&t.prototype.await.forEach(t=>t())}))}render(){this.options={captions:this.hasAttribute("captions")&&"false"!==this.getAttribute("captions"),margins:this.getAttribute("margins")||"4"},$(this).find("img").each((t,e)=>{var i=document.createElement("div");i.setAttribute("data-fancybox","gallery"),i.setAttribute("data-options",JSON.stringify({hash:!1})),e.alt&&i.setAttribute("data-caption",e.alt),i.setAttribute("href",e.src),$(e).wrap(i)}),$(this).justifiedGallery({captions:this.options.captions,margins:this.options.margins}),this.drawComplete()}}),customElements.define("mew-raw",class extends e{init(){var t=this.innerHTML;this.innerHTML="",this.attachShadow({mode:"closed"}).innerHTML=t,this.drawComplete()}})})})();