Skip to content

Commit

Permalink
Perf: 优化当下一条评论和上一条评论是同一首歌时不重新加载歌曲
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Mar 1, 2023
1 parent fc5505c commit bd0a05e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion layouts/shortcodes/mmt-netease.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{{- $version := "1.0.2" -}}
{{- $version := "1.0.3" -}}
{{- $mid := cond .IsNamedParams (.Get "mid") (.Get 0) | default "2280569152" -}}
{{- $autoplay := cond .IsNamedParams (.Get "autoplay") (.Get 1) | default false -}}

Expand Down
14 changes: 9 additions & 5 deletions static/shortcodes/mmt-netease/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const RNC = new (function () {
const $music = document.querySelector('.netease-music');
const $comment = document.querySelector('.comment-163');
let lastMusic = void 0;

/**
* 获取随机网易云评论
Expand All @@ -24,11 +25,14 @@ const RNC = new (function () {
$comment.querySelector('.comment-content').innerHTML = comment.data.content.replace('\n','<br/>');
$comment.querySelector('.music-name').innerHTML = comment.data.name;
$comment.querySelector('.artists-name').innerHTML = comment.data.artistsname;
const $player = document.createElement('meting-js');
$player.setAttribute('auto', comment.data.url);
$player.setAttribute('autoplay', autoplay);
$music.innerHTML = '';
$music.appendChild($player);
if (!lastMusic || (lastMusic !== comment.data.url)) {
const $player = document.createElement('meting-js');
$player.setAttribute('auto', comment.data.url);
$player.setAttribute('autoplay', autoplay);
$music.innerHTML = '';
$music.appendChild($player);
lastMusic = comment.data.url;
}
})
};

Expand Down

0 comments on commit bd0a05e

Please sign in to comment.