第130行: |
第130行: |
| n.classList.remove('template-render-cloak'); | | n.classList.remove('template-render-cloak'); |
| }); | | }); |
| + | |
| + | |
| + | /* 生成音频播放-s按钮 */ |
| + | (function (){ |
| + | var audios = document.getElementsByClassName('audio-player-s'); |
| + | var notValidAudio = /wpDestFile/; |
| + | var currentPlaying = null; |
| + | |
| + | for(var i = 0; i < audios.length; i++) { |
| + | var audio = audios[i]; |
| + | var linkEl = audio.firstElementChild; |
| + | |
| + | if (!linkEl) { |
| + | continue; |
| + | } |
| + | |
| + | var link = linkEl.href; |
| + | |
| + | if (notValidAudio.test(link)) { |
| + | continue; |
| + | } |
| + | |
| + | audio.innerHTML = ''; |
| + | audio.classList.add('has-audio-element'); |
| + | |
| + | var a = document.createElement('audio'); |
| + | |
| + | a.src = link; |
| + | a.preload = 'none'; |
| + | |
| + | a.onended = function () { |
| + | currentPlaying = null; |
| + | this.parentNode.classList.remove('audio-player-playing-s'); |
| + | }; |
| + | |
| + | var button = document.createElement('button'); |
| + | |
| + | button.classList.add('audio-player-button-s'); |
| + | button.append(a); |
| + | button.onclick = function () { |
| + | var a = this.firstElementChild; |
| + | |
| + | if (currentPlaying != null && currentPlaying != a) { |
| + | currentPlaying.pause(); |
| + | currentPlaying.currentTime = 0; |
| + | currentPlaying.parentNode.classList.remove('audio-player-playing-s'); |
| + | } |
| + | |
| + | if (a.paused) { |
| + | a.play(); |
| + | currentPlaying = a; |
| + | this.classList.add('audio-player-playing-s'); |
| + | this.classList.remove('audio-player-paused-s'); |
| + | } |
| + | else { |
| + | a.pause(); |
| + | this.classList.add('audio-player-paused-s'); |
| + | this.classList.remove('audio-player-playing-s'); |
| + | }; |
| + | }; |
| + | |
| + | audio.append(button); |
| + | }; |
| + | })(); |