15 lines
13 KiB
JavaScript
Raw Normal View History

2024-12-22 10:38:44 +08:00
(()=>{class i extends HTMLElement{constructor(){super(),this.hasAttribute("draw")||this.init()}drawComplete(){this.setAttribute("draw",!0)}}document.addEventListener("DOMContentLoaded",()=>{customElements.define("mew-hide",class extends i{init(){var t=$(this),i=t.closest(".main-content");this.options={target:i.attr("data-target"),id:i.attr("data-id")},this.options.target&&this.options.id&&((i=(i=localStorage.getItem(window.encrypt("mew-hide-"+this.options.target)))?JSON.parse(window.decrypt(i)):[]).includes(this.options.id)?(t.before(this.innerHTML),t.remove()):(i=0!==t.find("h1,h2,h3,h4,h5").length,this.setAttribute("hide",window.encrypt(this.innerHTML)),this.innerHTML="",i&&(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 i{init(){this.innerHTML=`<span>${this.innerText||"默认标题"}</span>`,this.drawComplete()}}),customElements.define("mew-music",class i extends HTMLElement{constructor(){super(),this.innerHTML=this.getAttribute("prompt")||"音乐播放器加载中...",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():i.prototype.load?i.prototype.await.push(()=>this.render()):(i.prototype.load=!0,i.prototype.await=[],new Promise(t=>{$("head").append('<link rel="stylesheet" href="https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.css">'),Utils.cachedScript("https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.js").done(()=>t()).fail(()=>t())}).then(()=>{this.render(),i.prototype.await&&i.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")||"音乐",url:this.getAttribute("url"),artist:this.getAttribute("artist")||"未知歌手",cover:this.getAttribute("cover"),lrc:this.getAttribute("lrc")||(this.options.lrcType=void 0)}];else{if(!this.hasAttribute("music-list"))return this.innerHTML="未指定播放的音乐!",t();var i=JSON.parse(this.getAttribute("music-list"));i.forEach(t=>{t.lrc=t.lrc||"",t.name=t.name||"音乐",t.artist=t.artist||"未知歌手",t.cover=t.cover||"/themes/theme-dream2-plus/assets/img/music.webp"}),this.options.audio=i}this.aplayer=new APlayer(this.options),t()}).catch(t=>{}):this.innerHTML="未开启音乐播放器!"}getAPlayer(){return this.aplayer}disconnectedCallback(){this.aplayer&&this.aplayer.destroy()}}),customElements.define("mew-bilibili",class extends i{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" st
2023-03-21 10:49:35 +08:00
<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">来源${t[this.options.type]||"网络来源"}${this.options.password?" | 提取码:"+this.options.password:""}</div>
</div>
<a class="mew-cloud-link" href="${this.options.url}" target="_blank" rel="noopener noreferrer nofollow">
2023-09-12 10:44:43 +08:00
<i class="ri-download-line"></i>
2023-03-21 10:49:35 +08:00
</a>
`,this.drawComplete()}}),customElements.define("mew-progress",class extends i{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">
2023-03-21 10:49:35 +08:00
<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 i{init(){this.options={title:this.getAttribute("title")||"",color:this.getAttribute("color")||"var(--theme)"},this.innerHTML=`
2023-03-21 10:49:35 +08:00
<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 i{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 i{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 i{init(){let t="",i=this.firstChild;for(;i;){var e;"MEW-TIMELINE-TITLE"===i.tagName?t+=`<div class="mew-timeline-title ${i.getAttribute("type")||""}"><span class="mew-timeline-title-elem">${i.innerHTML}</span></div>`:"MEW-TIMELINE-ITEM"===i.tagName&&(i.getAttribute("type"),e=i.getAttribute("title")?`<span class="mew-timeline-item-title">${i.getAttribute("title")}</span>`:"",t+=`<div class="mew-timeline-item ${i.getAttribute("type")||""}">${e}<div class="mew-timeline-item-content">${i.innerHTML}</div></div>`),i=i.nextElementSibling}this.innerHTML=t,this.drawComplete()}}),customElements.define("mew-btn",class extends i{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">${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 i{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" target="_blank" ${this.options.href?`href="${this.options.href}"`:""}><img class="quote-avatar-hexagon not-gallery" src="${this.options.avatar}"/></a>`:"",i=this.options.name?`<a class="mew-quote-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>${i}</div></div></div>`,this.drawComplete()}}),customElements.define("mew-link",class extends i{async init(){this.options={img:this.getAttribute("img"),href:this.getAttribute("href")||"",title:this.getAttribute("title"),slug:this.getAttribute("slug"),id:this.getAttribute("id"),type:this.getAttribute("type")||"post",desc:this.innerHTML},(this.options.id||this.options.slug)&&await Utils.request({url:this.options.id?`/api/content/${this.options.type}s/`+this.options.id:`/api/content/${this.options.type}s/slug?slug=`+this.options.slug,method:"GET"}).then(t=>{this.options.img=this.options.img||t.thumbnail,this.options.href=this.options.title||t.fullPath,this.options.title=this.options.title||t.title,this.options.desc=this.options.desc||t.summary}).catch(t=>{this.options.desc="Error: "+t});var t=this.options.img?`<span class="mew-link-image"><img class="link-image not-gallery" src="${this.options.img}"/></span>`:"",i=this.options.desc?`<span class="info-desc">${this.options.desc}</span>`:`<span class="mew-link-href info-desc">${this.options.href}</span>`;this.innerHTML=`<a class="mew-link" target="_blank" href="${this.options.href}"><span class="mew-link-info"><p class="info-title">${this.options.title||"我分享了一个网站"}</p>${i}</span>${t}</a>`,this.drawComplete()}}),customElements.define("mew-video",class extends i{init(){this.options={src:this.getA