小 |
小 |
||
第16行: | 第16行: | ||
n.setAttribute('title', '下载'); | n.setAttribute('title', '下载'); | ||
}); | }); | ||
+ | /* 生成音频播放按钮 */ | ||
+ | (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'; | ||
+ | a.onended = function(){ | ||
+ | this.parentNode.classList.remove('audio-player-playing'); | ||
+ | }; | ||
+ | var button = document.createElement('button'); | ||
+ | button.classList.add('audio-player-button'); | ||
+ | button.append(a); | ||
+ | button.onclick = function(){ | ||
+ | var a = this.firstElementChild; | ||
+ | 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'); | ||
+ | }; | ||
+ | }; | ||
+ | audio.append(button); | ||
+ | }; | ||
+ | })(); |
2021年4月2日 (五) 00:01的版本
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */ /* 补齐丢失的MediaWiki快捷键 */ $('#ca-edit').attr('accesskey','e'); $('#ca-edit').attr('title','编辑本页[alt-shift-e]'); $('#ca-talk').attr('accesskey','t'); $('#ca-talk').attr('title','关于内容页面的讨论[alt-shift-t]'); /* 右上角添加强制刷新按钮 */ $('.wds-button-group #p-more .wds-list:not(.ns--1 .wds-list)').append('<li id="m-page-purge"><a href="?action=purge">强制刷新</a></li>'); /* 处理直接下载的链接问题 */ $('.download-link > a').each(function (_, n) { n.setAttribute('target', '_blank'); n.setAttribute('download', n.getAttribute('title')); n.setAttribute('title', '下载'); }); /* 生成音频播放按钮 */ (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'; a.onended = function(){ this.parentNode.classList.remove('audio-player-playing'); }; var button = document.createElement('button'); button.classList.add('audio-player-button'); button.append(a); button.onclick = function(){ var a = this.firstElementChild; 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'); }; }; audio.append(button); }; })();