第2行: |
第2行: |
| | | |
| /* 生成音频播放按钮 */ | | /* 生成音频播放按钮 */ |
− | (function(){
| |
− | var audios = document.getElementsByClassName("audio-player");
| |
− | var notValidAudio = /wpDestFile/;
| |
− | for(var i=0;i<audios.length;i++){
| |
− | var audio = audios[i];
| |
− | var link = audio.firstElementChild.href;
| |
− | if(notValidAudio.test(link)) continue;
| |
− | audio.innerHTML = "";
| |
− | var a = document.createElement('audio');
| |
− | a.src = link;
| |
− | a.preload = 'none';
| |
− | audio.append(a);
| |
− | var button = document.createElement('button');
| |
− | button.onclick = function(){
| |
− | var audio = this.parentNode;
| |
− | var a = audio.children[0];
| |
− | if (a.paused){
| |
− | a.play();
| |
− | this.classList.add('audio-player-playing');
| |
− | this.classList.remove('audio-player-paused');
| |
− | }else{
| |
− | a.pause();
| |
− | this.classList.add('audio-player-paused');
| |
− | this.classList.remove('audio-player-playing');
| |
− | };
| |
− | };
| |
| | | |
− | a.onended = function(){
| |
− | this.parentNode.children[1].classList.remove('audio-player-playing');
| |
− | };
| |
− |
| |
− | audio.append(button);
| |
− | };
| |
− | })();
| |
| | | |
| /* 生成b站播放窗口 */ | | /* 生成b站播放窗口 */ |