|
|
| (未显示同一用户的4个中间版本) |
| 第1行: |
第1行: |
| (function(mw, $) { | | /* PWA安装测试 */ |
| 'use strict'; | | (function() { |
| | | var btn = document.getElementById('pwa-test-btn'); |
| function initBmvPlayer(wrapper) {
| | var savedPrompt = null; |
| var $wrapper = $(wrapper);
| | window.addEventListener('beforeinstallprompt', function(e) { |
|
| | e.preventDefault(); |
| var songName = $wrapper.data('song-name');
| | savedPrompt = e; |
| var rawDifficulties = $wrapper.data('difficulties');
| | if (btn) btn.style.display = 'block'; |
| | | }); |
| var $difficultyDiv = $wrapper.find('.difficulty-div'); | | if (btn) { |
| var $ratioDiv = $wrapper.find('.ratio-div'); | | btn.addEventListener('click', function() { |
| var $outputSpan = $wrapper.find('.output-span'); | | if (savedPrompt) { |
|
| | savedPrompt.prompt(); |
| var difficultyColors = {
| | savedPrompt = null; |
| "EZ": "#57E4C4", "HD": "#FDBA61", "IN": "#FE8661", "AT": "#4C364B"
| | } else { |
| };
| | alert('暂时无法安装(可能已安装或不支持)'); |
| | |
| function parseDifficulties(input) {
| |
| if (!input) return null;
| |
| try {
| |
| return input.split(',').map(function(item) {
| |
| var match = item.trim().match(/^([A-Za-z]+)(\d+)$/);
| |
| if (!match) throw new Error('Invalid format');
| |
| return (match[1].toUpperCase() + ' ' + match[2]);
| |
| }); | |
| } catch (e) { | |
| console.error("Error parsing difficulties:", input, e); | |
| return null;
| |
| } | | } |
| } | | }); |
| | |
| var difficultyStates = parseDifficulties(rawDifficulties);
| |
| | |
| if (!songName || !difficultyStates || difficultyStates.length === 0) {
| |
| $wrapper.find('table').html('<div style="color:red; padding:10px; text-align:center;">错误: 缺少或无效的曲名/难度参数。</div>');
| |
| return;
| |
| }
| |
| | |
| $difficultyDiv.attr('data-states', JSON.stringify(difficultyStates));
| |
| | |
| function updateOutput() {
| |
| var difficulty = $difficultyDiv.text().split(' ')[0];
| |
| var ratio = $ratioDiv.text().replace(':', '-');
| |
| var encodedSongName = encodeURIComponent(songName);
| |
| var videoUrl = 'https://pan.rizwiki.cn/d/' + ratio + '_' + encodedSongName + '_' + difficulty + '.mp4';
| |
|
| |
| var isMobile = window.matchMedia("(max-width: 600px)").matches;
| |
| var videoHeightStyle = isMobile ? '' : 'height:100%;';
| |
| | |
| $outputSpan.html('<video class="html5media-video" src="' + videoUrl + '" controls preload="metadata" loading="lazy" style="' + videoHeightStyle + ' object-fit:contain;"></video>');
| |
| }
| |
| | |
| function cycleDifficulty() {
| |
| var states = JSON.parse($difficultyDiv.attr('data-states'));
| |
| var current = parseInt($difficultyDiv.attr('data-current'), 10);
| |
| current = (current + 1) % states.length;
| |
|
| |
| var nextState = states[current];
| |
| $difficultyDiv.text(nextState);
| |
| $difficultyDiv.attr('data-current', current.toString());
| |
|
| |
| var difficultyType = nextState.split(' ')[0];
| |
| $difficultyDiv.parent().css('background-color', difficultyColors[difficultyType] || '#FFFFFF');
| |
|
| |
| updateOutput();
| |
| }
| |
| | |
| function cycleRatio() {
| |
| var states = JSON.parse($ratioDiv.attr('data-states'));
| |
| var current = parseInt($ratioDiv.attr('data-current'), 10);
| |
| current = (current + 1) % states.length;
| |
|
| |
| $ratioDiv.text(states[current]);
| |
| $ratioDiv.attr('data-current', current.toString());
| |
|
| |
| updateOutput();
| |
| }
| |
| | |
| $difficultyDiv.on('click', cycleDifficulty);
| |
| $ratioDiv.parent().on('click', cycleRatio);
| |
| | |
| // 初始化
| |
| (function initialize() {
| |
| var firstDiff = difficultyStates[0];
| |
| var diffType = firstDiff.split(' ')[0];
| |
|
| |
| $difficultyDiv.text(firstDiff);
| |
| $difficultyDiv.parent().css('background-color', difficultyColors[diffType]);
| |
|
| |
| updateOutput();
| |
| })();
| |
| } | | } |
| | | })(); |
| mw.hook('wikipage.content').add(function($content) {
| |
| $content.find('.bmv-player-uninitialized').each(function() {
| |
| // 初始化播放器
| |
| initBmvPlayer(this);
| |
| $(this).removeClass('bmv-player-uninitialized');
| |
| });
| |
| });
| |
| | |
| })(mediaWiki, jQuery); | |
/* PWA安装测试 */
(function() {
var btn = document.getElementById('pwa-test-btn');
var savedPrompt = null;
window.addEventListener('beforeinstallprompt', function(e) {
e.preventDefault();
savedPrompt = e;
if (btn) btn.style.display = 'block';
});
if (btn) {
btn.addEventListener('click', function() {
if (savedPrompt) {
savedPrompt.prompt();
savedPrompt = null;
} else {
alert('暂时无法安装(可能已安装或不支持)');
}
});
}
})();