第196行: | 第196行: | ||
− | + | (function () { | |
− | + | var Bikit = Bikit || {}; | |
− | Bikit.kits.audio = { | + | Bikit.kits = Bikit.kits || {}; |
− | + | Bikit.kits.audio = { | |
− | + | isReady: false, | |
− | + | ready: function () { | |
− | + | this.isReady = true; | |
− | + | window.resetPlayer = function () { | |
− | + | this.pause(); | |
− | + | this.currentTime = 0; | |
− | + | $(this).parent().find('.icon-btn').toggleClass('icon-play'); | |
− | + | }; | |
− | + | $("head").prepend('<style>.default-player audio{display:none;}.default-player .audio-controller{display:inline-block;width:30px;height:30px;padding:0;position:relative;text-align:center;background-color:#f8f9fa;cursor:pointer;border-radius:50%;border:1px solid #dddddd;box-sizing:border-box;}.default-player .audio-controller .icon-btn{display:inline-block;width:100%;height:100%;background:url("https://patchwiki.biligame.com/images/szqy/0/05/1tg75ar2mq110pxbmcze33cy0xlbrk0.png");background-size:100% 100%;background-repeat:no-repeat;background-position:center;} .default-player .audio-controller .icon-play{background:url("https://patchwiki.biligame.com/images/szqy/d/db/afe454y0obdwci3azwzc66j7jx9ge0r.png");background-size:100% 100%;background-repeat:no-repeat;background-position:center;}</style>'); | |
− | + | $(".mw-parser-output").on("click", ".bikited-audio .audio-controller", function () { | |
− | + | var controlBtn = $(this).find('.icon-btn'); | |
− | + | var audio = $(this).parent().find('audio')[0]; | |
− | + | if (controlBtn.hasClass('icon-play')) { | |
− | + | audio.pause(); | |
− | + | controlBtn.toggleClass('icon-play'); | |
− | + | } else { | |
− | + | $("audio").each(function () { | |
− | + | if (this.paused) return true; | |
− | + | this.pause(); | |
− | + | audio.currentTime = 0; | |
− | + | $(this).parent().find('.icon-btn').toggleClass('icon-play'); | |
− | + | }); | |
− | + | if (!audio.duration) audio.addEventListener("ended", resetPlayer); | |
− | audio.play(); | + | controlBtn.toggleClass('icon-play'); |
+ | audio.play(); | ||
+ | } | ||
+ | }); | ||
+ | }, | ||
+ | main: function (ele, opts) { | ||
+ | if (!opts.src) return $(ele).hide(); | ||
+ | var $audio = $("<audio>").attr({ | ||
+ | "src": opts.src, | ||
+ | "controls": opts.controls || "", | ||
+ | "preload": opts.preload || "none" | ||
+ | }); | ||
+ | $(ele).addClass("bikited-audio").append($audio); | ||
+ | if (opts.mode === "default") { | ||
+ | $(ele).addClass("default-player").append( | ||
+ | '<div class="audio-controller"><div class="play-pause"><div class="icon-btn"></div></div></div>'); | ||
+ | if (!this.isReady) this.ready(); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | } | + | }; |
− | }; | + | })(); |
2023年11月23日 (四) 19:54的版本
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */ /* 生成b站播放窗口 */ (function(){ var bVideos = document.getElementsByClassName('bilibili'); for(var i=0;i<bVideos.length;i++){ var bVideo = bVideos[i]; var bvid = bVideo.textContent.trim(); bVideo.innerHTML = ''; var iframe = document.createElement('iframe'); iframe.src = 'https://player.bilibili.com/player.html?page=1&bvid='+bvid; iframe.scrolling = 'no'; iframe.border = '0'; iframe.frameborder = 'no'; iframe.framespacing='0'; iframe.allowfullscreen='true'; bVideo.append(iframe); } })(); /* 补齐丢失的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', '下载'); }); /* 生成音频播放按钮 */ (window.onload = function (){ var audios = document.getElementsByClassName('audio-player'); 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'); }; var button = document.createElement('button'); button.classList.add('audio-player-button'); 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'); } if (a.paused) { a.play(); currentPlaying = a; 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); }; })(); /* 重新布局评论区 */ /* (function () { $('#allcomments .c-item').each(function(_, c) { var $commentItem = $(c); var $score = $commentItem.find('.c-score'); $commentItem.prepend($score); $commentItem.addClass('c-layout'); }); })(); */ /* 使用占位图来代替受损图像链接(基本是图还没上传的) */ $('a.new').each(function(_, n) { var href = n.getAttribute('href'); var isImage = /\.(png|jpe?g|svg|gif)$/.test(href); if (isImage) { // 将这个链接加上一个 class n.classList.add('unresolved-image'); // 其文本内容则是设置的宽高 n.style.width = n.textContent; n.style.height = n.textContent; } }); /* 移除渲染延迟 Cloak */ $('.template-render-cloak').each(function(_, n) { 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); }; })(); (function () { var Bikit = Bikit || {}; Bikit.kits = Bikit.kits || {}; Bikit.kits.audio = { isReady: false, ready: function () { this.isReady = true; window.resetPlayer = function () { this.pause(); this.currentTime = 0; $(this).parent().find('.icon-btn').toggleClass('icon-play'); }; $("head").prepend('<style>.default-player audio{display:none;}.default-player .audio-controller{display:inline-block;width:30px;height:30px;padding:0;position:relative;text-align:center;background-color:#f8f9fa;cursor:pointer;border-radius:50%;border:1px solid #dddddd;box-sizing:border-box;}.default-player .audio-controller .icon-btn{display:inline-block;width:100%;height:100%;background:url("https://patchwiki.biligame.com/images/szqy/0/05/1tg75ar2mq110pxbmcze33cy0xlbrk0.png");background-size:100% 100%;background-repeat:no-repeat;background-position:center;} .default-player .audio-controller .icon-play{background:url("https://patchwiki.biligame.com/images/szqy/d/db/afe454y0obdwci3azwzc66j7jx9ge0r.png");background-size:100% 100%;background-repeat:no-repeat;background-position:center;}</style>'); $(".mw-parser-output").on("click", ".bikited-audio .audio-controller", function () { var controlBtn = $(this).find('.icon-btn'); var audio = $(this).parent().find('audio')[0]; if (controlBtn.hasClass('icon-play')) { audio.pause(); controlBtn.toggleClass('icon-play'); } else { $("audio").each(function () { if (this.paused) return true; this.pause(); audio.currentTime = 0; $(this).parent().find('.icon-btn').toggleClass('icon-play'); }); if (!audio.duration) audio.addEventListener("ended", resetPlayer); controlBtn.toggleClass('icon-play'); audio.play(); } }); }, main: function (ele, opts) { if (!opts.src) return $(ele).hide(); var $audio = $("<audio>").attr({ "src": opts.src, "controls": opts.controls || "", "preload": opts.preload || "none" }); $(ele).addClass("bikited-audio").append($audio); if (opts.mode === "default") { $(ele).addClass("default-player").append( '<div class="audio-controller"><div class="play-pause"><div class="icon-btn"></div></div></div>'); if (!this.isReady) this.ready(); } } }; })();