Skip to content

Commit

Permalink
扩展<mew-music>组件,可用于自定义侧边栏播放器
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsoftking committed Dec 19, 2024
1 parent 9a42b9b commit ae2b6a3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions src/js/mew-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ document.addEventListener('DOMContentLoaded', () => {
this.innerHTML = '音乐播放器加载中...'
this.options = {
container: this,
fixed: this.hasAttribute('fixed') || false,
mutex: this.hasAttribute('mutex') || true,
theme: this.getAttribute('theme') || 'var(--theme)',
loop: this.getAttribute('loop') || 'all',
autoplay: this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false',
Expand All @@ -77,15 +79,16 @@ document.addEventListener('DOMContentLoaded', () => {
listMaxHeight: this.getAttribute('listMaxHeight') || 450,
mimi: this.getAttribute('mimi') || false,
order: this.getAttribute('order') || 'list',
storageName: this.getAttribute('storageName') || 'aplayer-setting',
}
if (!('APlayer' in window)) {
if (!MewMusic.prototype.load) {
MewMusic.prototype.load = true
MewMusic.prototype.await = []
new Promise((resolve) => {
const $head = $('head')
$head.append('<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/APlayer.min.css">')
Utils.cachedScript('https://unpkg.com/[email protected]/dist/APlayer.min.js')
$head.append('<link rel="stylesheet" href="/themes/theme-dream2-plus/assets/lib/[email protected]/APlayer.min.css">')
Utils.cachedScript('/themes/theme-dream2-plus/assets/lib/[email protected]/APlayer.min.js')
.done(() => resolve())
.fail(() => resolve())
}).then(() => {
Expand Down Expand Up @@ -128,7 +131,14 @@ document.addEventListener('DOMContentLoaded', () => {
lrc: this.getAttribute('lrc') || (this.options.lrcType = undefined),
}]
} else if (this.hasAttribute('music-list')) {
this.options.audio = JSON.parse(this.getAttribute('music-list'))
var musicList = JSON.parse(this.getAttribute('music-list'))
musicList.forEach((item) => {
item.lrc = item.lrc || ''
item.name = item.name || '音乐'
item.artist = item.artist || '未知歌手'
item.cover = item.cover || '/themes/theme-dream2-plus/assets/img/music.webp'
})
this.options.audio = musicList
} else {
this.innerHTML = '未指定播放的音乐!'
return resolve()
Expand Down Expand Up @@ -425,7 +435,7 @@ document.addEventListener('DOMContentLoaded', () => {
MewPhotos.prototype.load = true
MewPhotos.prototype.await = []
new Promise((resolve) => {
Utils.cachedScript('https://unpkg.com/[email protected]/dist/js/jquery.justifiedGallery.min.js')
Utils.cachedScript('/themes/theme-dream2-plus/assets/lib/[email protected]/dist/js/jquery.justifiedGallery.min.js')
.done(() => resolve())
.fail(() => resolve())
}).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion templates/assets/css/mew-custom.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion templates/assets/css/style.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit ae2b6a3

Please sign in to comment.