2024-05-07 12:31:42 +08:00

1 line
19 KiB
JavaScript
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.

(()=>{var __webpack_modules__={"./src/js/mew-custom.js":()=>{eval("class MewElement extends HTMLElement {\r\n constructor() {\r\n super()\r\n if (this.hasAttribute('draw')) return\r\n this.init()\r\n }\r\n\r\n drawComplete() {\r\n this.setAttribute('draw', true)\r\n }\r\n}\r\n\r\ndocument.addEventListener('DOMContentLoaded', () => {\r\n customElements.define(\r\n 'mew-hide',\r\n class MewHide extends MewElement {\r\n init() {\r\n let $this = $(this)\r\n const $mainContent = $this.closest('.main-content')\r\n this.options = {\r\n target: $mainContent.attr('data-target'),\r\n id: $mainContent.attr('data-id')\r\n }\r\n if (this.options.target && this.options.id) {\r\n let commentIds = localStorage.getItem(window.encrypt('mew-hide-' + this.options.target))\r\n commentIds = commentIds ? JSON.parse(window.decrypt(commentIds)) : []\r\n if (commentIds.includes(this.options.id)) {\r\n $this.before(this.innerHTML)\r\n $this.remove()\r\n } else {\r\n let isToc = $this.find('h1,h2,h3,h4,h5').length !== 0\r\n this.setAttribute('hide', window.encrypt(this.innerHTML))\r\n this.innerHTML = ''\r\n if(isToc) {\r\n this.setAttribute('toc', true)\r\n commonContext.initTocAndNotice()\r\n }\r\n this.onclick = function () {\r\n let $haloComment = $(`halo-comment[id='${this.options.id}'][type='${this.options.target.substring(0, this.options.target.length - 1)}']`)\r\n if ($haloComment.length === 0 || $haloComment.is(':hidden')) {\r\n return\r\n }\r\n Utils.animateScroll($haloComment[0], 20, (window.innerHeight || document.documentElement.clientHeight) / 4)\r\n }\r\n }\r\n }\r\n this.drawComplete()\r\n }\r\n }\r\n )\r\n\r\n customElements.define(\r\n 'mew-subtitle',\r\n class MewSubtitle extends MewElement {\r\n init() {\r\n this.innerHTML = `<span>${this.innerText || '默认标题'}</span>`\r\n this.drawComplete()\r\n }\r\n }\r\n )\r\n\r\n customElements.define(\r\n 'mew-music',\r\n class MewMusic extends HTMLElement {\r\n\r\n constructor() {\r\n super()\r\n this.innerHTML = '音乐播放器加载中...'\r\n this.options = {\r\n container: this,\r\n theme: this.getAttribute('theme') || 'var(--theme)',\r\n loop: this.getAttribute('loop') || 'all',\r\n autoplay: this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false',\r\n lrcType: 3,\r\n }\r\n if (!('APlayer' in window)) {\r\n if (!MewMusic.prototype.load) {\r\n MewMusic.prototype.load = true\r\n MewMusic.prototype.await = []\r\n new Promise((resolve) => {\r\n const $head = $('head')\r\n $head.append('<link rel=\"stylesheet\" href=\"https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.css\">')\r\n Utils.cachedScript('https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.js')\r\n .done(() => resolve())\r\n .fail(() => resolve())\r\n }).then(() => {\r\n this.render()\r\n MewMusic.prototype.await && MewMusic.prototype.await.forEach(n => n())\r\n })\r\n } else {\r\n MewMusic.prototype.await.push(() => this.render())\r\n }\r\n } else {\r\n this.render()\r\n }\r\n }\r\n\r\n render() {\r\n if (!('APlayer' in window)) {\r\n this.innerHTML = '未开启音乐播放器!'\r\n return\r\n }\r\n // eslint-disable-next-line no-async-promise-executor\r\n new Promise(async (resolve) => {\r\n if (this.hasAttribute('song')) {\r\n this.options.audio = await fetch(\r\n 'https://api.i-meto.com/meting/api?server=netease&type=song&id=' +\r\n this.getAttribute('song')\r\n ).then((response) => response.json())\r\n } else if (this.hasAttribute('playlist')) {\r\n this.options.listFolded = this.getAttribute('fold')\r\n this.options.order = this.getAttribute('order')\r\n this.options.audio = await fetch(\r\n 'https://api.i-meto.com/meting/api?server=netease&type=playlist&id=' +\r\n this.getAttribute('playlist')\r\n ).then((response) => response.json())\r\n } else if (this.hasAttribute('url')) {\r\n this.options.audio = [{\r\n name: this.getAttribute('name') || '音乐',\r\n url: this.getAttribute('url'),\r\n artist: this.getAttribute('artist') || '未知歌手',\r\n cover: this.getAttribute('cover'),\r\n lrc: this.getAttribute('lrc') || (this.options.lrcType = undefined),\r\n }]\r\n } else {\r\n this.innerHTML = '未指定播放的音乐!'\r\n return resolve()\r\n }\r\n this.aplayer = new APlayer(this.options)\r\n resolve()\r\n })\r\n .catch((e) => {})\r\n }\r\n\r\n disconnectedCallback() {\r\n this.aplayer && this.aplayer.destroy()\r\n }\r\n }\r\n )\r\n\r\n customElements.define(\r\n 'mew-bilibili',\r\n class MewBilibili extends MewElement {\r\n init() {\r\n this.options = {\r\n bvid: this.getAttribute('bvid'),\r\n width: /^\\d{1,3}%$/.test(this.getAttribute('width'))\r\n ? this.getAttribute('width')\r\n : '100%',\r\n }\r\n if (this.options.bvid) {\r\n this.style.padding = `calc(${this.options.width} * 0.3) 0`\r\n this.innerHTML = `<iframe allowfullscreen=\"true\" src=\"//player.bilibili.com/player.html?bvid=${this.options.bvid}&page=1\" style=\"width: ${this.options.width};\"></iframe>`\r\n } else this.innerHTML = 'bvid未填写'\r\n this.drawComplete()\r\n }\r\n }\r\n )\r\n\r\n customElements.define(\r\n 'mew-tabs',\r\n class MewTabs extends MewElement {\r\n init() {\r\n const $tabPage = $(this).children('mew-tab-page')\r\n if ($tabPage.length === 0) {\r\n this.innerHTML = '没有标签页!'\r\n this.drawComplete()\r\n return\r\n }\r\n let navs = ''\r\n let contents = ''\r\n let active = false\r\n $tabPage.each((index, elem) => {\r\n let title = elem.getAttribute('title') || '默认标签'\r\n let id = `${index}-${new Date().getTime()}`\r\n if (!active && elem.hasAttribute('active')) {\r\n active = true\r\n navs += `<div class=\"active\" data-id=\"#${id}\">${title}</div>`\r\n contents += `<div class=\"active\" id=\"${id}\">${elem.innerHTML}</div>`\r\n } else {\r\n navs += `<div data-id=\"#${id}\">${title}</div>`\r\n contents += `<div id=\"${id}\">${elem.innerHTML}</div>`\r\n }\r\n })\r\n this.innerHTML = `<div class=\"tabs-head\">${navs}</div><div class=\"tabs-body\">${contents}</div>`\r\n !active && $(this).find('div>div:first-child').addClass('active')\r\n this.drawComplete()\r\n }\r\n\r\n connectedCallback() {\r\n $(this).find('.tabs-head').on('click', 'div:not(.active)', function () {\r\n const $container = $(this).parent().parent()\r\n $container.find('.active').removeClass('active')\r\n $(this).addClass('active')\r\n $container.find($(this).attr('data-id')).addClass('active')\r\n })\r\n }\r\n }\r\n )\r\n\r\n customElements.define(\r\n 'mew-cloud',\r\n class MewCloud extends MewElement {\r\n init() {\r\n this.options = {\r\n type: this.getAttribute('type') || 'default',\r\n title: this.innerText || '资源文件分享',\r\n url: this.getAttribute('url'),\r\n password: this.getAttribute('password'),\r\n }\r\n const type = {\r\n default: '网络来源',\r\n 360: '360云盘',\r\n bd: '百度网盘',\r\n wy: '微云',\r\n ali: '阿里云盘',\r\n github: 'Github仓库',\r\n gitee: 'Gitee仓库',\r\n lz: '蓝奏云网盘',\r\n }\r\n this.innerHTML = `\r\n\t\t\t\t\t<div class=\"mew-cloud-logo type-${type[this.options.type] ? this.options.type : 'default'}\"></div>\r\n\t\t\t\t\t<div class=\"mew-cloud-desc\">\r\n\t\t\t\t\t\t<div class=\"mew-cloud-desc-title\">${this.options.title}</div>\r\n\t\t\t\t\t\t<div class=\"mew-cloud-desc-type\">来源:${type[this.options.type] || '网络来源'}${this.options.password ? ' | 提取码:' + this.options.password : ''}</div>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<a class=\"mew-cloud-link\" href=\"${this.options.url}\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\r\n\t\t\t\t\t\t<i class=\"ri-download-line\"></i>\r\n\t\t\t\t\t</a>\r\n\t\t\t\t`\r\n this.drawComplete()\r\n }\r\n }\r\n )\r\n\r\n customElements.define(\r\n 'mew-progress',\r\n class MewProgress extends MewElement {\r\n init() {\r\n this.options = {\r\n value: /^\\d{1,3}%$/.test(this.getAttribute('value'))\r\n ? this.getAttribute('value')\r\n : '50%',\r\n color: this.getAttribute('color') || 'var(--theme)',\r\n }\r\n this.innerHTML = `<div class=\"mew-progress-bar\">\r\n\t\t\t\t\t\t\t\t\t<div class=\"mew-progress-bar-inner\" style=\"width: ${this.options.value}; background: ${this.options.color};\"></div>\r\n\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t\t<div class=\"mew-progress-value\">${this.options.value}</div>`\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-panel',\r\n class MewPanel extends MewElement {\r\n init() {\r\n this.options = {\r\n title: this.getAttribute('title') || '',\r\n color: this.getAttribute('color') || 'var(--theme)',\r\n }\r\n this.innerHTML = `\r\n <div class=\"mew-panel-title\">${this.options.title}</div>\r\n <div class=\"mew-panel-body\">${this.innerHTML}</div>`\r\n this.style.background = this.options.color\r\n this.style.color = this.options.color\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-message',\r\n class MewMessage extends MewElement {\r\n init() {\r\n this.options = {\r\n type: /^(success|info|warning|error)$/.test(\r\n this.getAttribute('type')\r\n )\r\n ? this.getAttribute('type')\r\n : 'info',\r\n content: this.innerHTML || '消息内容',\r\n }\r\n this.innerHTML = this.options.content\r\n this.setAttribute('type', this.options.type)\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-hr',\r\n class MewHr extends MewElement {\r\n init() {\r\n this.startColor = this.getAttribute('startColor') || '#01d0ff'\r\n this.endColor = this.getAttribute('endColor') || '#fc3e85'\r\n 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%)`\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-timeline',\r\n class MewTimeline extends MewElement {\r\n init() {\r\n let content = ''\r\n let child = this.firstChild\r\n while (child) {\r\n if (child.tagName === 'MEW-TIMELINE-TITLE') {\r\n content += `<div class=\"mew-timeline-title ${child.getAttribute('type') || ''}\"><span class=\"mew-timeline-title-elem\">${child.innerHTML}</span></div>`\r\n } else if (child.tagName === 'MEW-TIMELINE-ITEM') {\r\n const type = child.getAttribute('type') || ''\r\n const title = child.getAttribute('title') ? `<span class=\"mew-timeline-item-title\">${child.getAttribute('title')}</span>` : ''\r\n content += `<div class=\"mew-timeline-item ${child.getAttribute('type') || ''}\">${title}<div class=\"mew-timeline-item-content\">${child.innerHTML}</div></div>`\r\n }\r\n child = child.nextElementSibling\r\n }\r\n this.innerHTML = content\r\n this.drawComplete()\r\n }\r\n }\r\n )\r\n\r\n customElements.define(\r\n 'mew-btn',\r\n class MewBtn extends MewElement {\r\n init() {\r\n this.options = {\r\n color: this.getAttribute('color') || 'var(--theme)',\r\n href: this.getAttribute('href'),\r\n target: this.getAttribute('target') || '_blank',\r\n icon: this.getAttribute('icon'),\r\n }\r\n this.innerHTML = `<a class=\"mew-btn\">${this.options.icon ? `<i class=\"${this.options.icon}\"></i>` : ''}${this.innerHTML}</a>`\r\n const btn = this.querySelector('a.mew-btn')\r\n this.options.href && (btn.href = this.options.href, btn.target = this.options.target)\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-quote',\r\n class MewQuote extends MewElement {\r\n init() {\r\n this.options = {\r\n avatar: this.getAttribute('avatar'),\r\n href: this.getAttribute('href'),\r\n name: this.getAttribute('name'),\r\n }\r\n const avatarElem = 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>` : ''\r\n const nameElem = this.options.name ? `<a class=\"mew-quote-name\" target=\"_blank\" ${this.options.href ? `href=\"${this.options.href}\"` : ''}>${this.options.name}</a>` : ''\r\n this.innerHTML = `<div class=\"mew-quote\"><div class=\"quote-container\">${avatarElem}<div class=\"mew-quote-info\"><p class=\"mew-quote-content\">${this.innerHTML}</p>${nameElem}</div></div></div>`\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-link',\r\n class MewLink extends MewElement {\r\n async init() {\r\n this.options = {\r\n img: this.getAttribute('img'),\r\n href: this.getAttribute('href') || '',\r\n title: this.getAttribute('title'),\r\n slug: this.getAttribute('slug'),\r\n id: this.getAttribute('id'),\r\n type: this.getAttribute('type') || 'post',\r\n desc: this.innerHTML\r\n }\r\n if (this.options.id || this.options.slug) {\r\n await Utils.request({\r\n url: this.options.id? `/api/content/${this.options.type}s/${this.options.id}` : `/api/content/${this.options.type}s/slug?slug=${this.options.slug}`,\r\n method: 'GET',\r\n })\r\n .then(res=>{\r\n this.options.img = this.options.img || res.thumbnail\r\n this.options.href = this.options.title || res.fullPath\r\n this.options.title = this.options.title || res.title\r\n this.options.desc = this.options.desc || res.summary\r\n })\r\n .catch(error => {\r\n this.options.desc = `Error: ${error}`\r\n })\r\n }\r\n const imageElem = this.options.img ? `<span class=\"mew-link-image\"><img class=\"link-image not-gallery\" src=\"${this.options.img}\"/></span>` : ''\r\n const descElem = this.options.desc ? `<span class=\"info-desc\">${this.options.desc}</span>` : `<span class=\"mew-link-href info-desc\">${this.options.href}</span>`\r\n 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>${descElem}</span>${imageElem}</a>`\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-video',\r\n class MewVideo extends MewElement {\r\n init() {\r\n this.options = {\r\n src: this.getAttribute('src'),\r\n type: this.getAttribute('type'),\r\n autoplay: this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false',\r\n controls: this.getAttribute('controls') !== 'false',\r\n loop: this.hasAttribute('loop') && this.getAttribute('loop') !== 'false',\r\n muted: this.hasAttribute('muted') && this.getAttribute('muted') !== 'false', // 静音播放\r\n preload: this.hasAttribute('preload') && this.getAttribute('preload') !== 'false',\r\n poster: this.getAttribute('poster'), // 加载图片\r\n width: /^\\d{1,3}%$/.test(this.getAttribute('width'))\r\n ? this.getAttribute('width')\r\n : '100%',\r\n }\r\n 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}\"` : ''}>不支持视频播放器!</video>`\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-photos',\r\n class MewPhotos extends MewElement {\r\n init() {\r\n if (!($.fn.justifiedGallery)) {\r\n if (!MewPhotos.prototype.load) {\r\n MewPhotos.prototype.load = true\r\n MewPhotos.prototype.await = []\r\n new Promise((resolve) => {\r\n Utils.cachedScript('https://unpkg.com/justifiedGallery@3.8.1/dist/js/jquery.justifiedGallery.min.js')\r\n .done(() => resolve())\r\n .fail(() => resolve())\r\n }).then(() => {\r\n this.render()\r\n MewPhotos.prototype.await && MewPhotos.prototype.await.forEach(n => n())\r\n })\r\n } else {\r\n MewPhotos.prototype.await.push(() => this.render())\r\n }\r\n } else {\r\n this.render()\r\n }\r\n }\r\n render() {\r\n this.options = {\r\n captions: this.hasAttribute('captions') && this.getAttribute('captions') !== 'false',\r\n margins: this.getAttribute('margins') || '4'\r\n }\r\n $(this).find('img').each((i, elem) => {\r\n $(elem).wrap(`<div data-fancybox=\"gallery\" ${elem.alt ? 'data-caption=\"' + elem.alt + '\"' : ''} href=\"${elem.src}\"></div>`)\r\n })\r\n $(this).justifiedGallery({captions: this.options.captions, margins: this.options.margins})\r\n this.drawComplete()\r\n }\r\n })\r\n\r\n customElements.define(\r\n 'mew-raw',\r\n class MewRaw extends MewElement {\r\n init() {\r\n let html = this.innerHTML\r\n this.innerHTML = ''\r\n const shadowRoot = this.attachShadow({ mode: 'closed' })\r\n shadowRoot.innerHTML = html\r\n this.drawComplete()\r\n }\r\n }\r\n )\r\n})\n\n//# sourceURL=webpack://halo-theme-dream2.0-plus/./src/js/mew-custom.js?")}},__webpack_exports__={};__webpack_modules__["./src/js/mew-custom.js"]()})();