|
|
| 第1行: |
第1行: |
| (function(mw, $) {
| |
| 'use strict';
| |
|
| |
|
| function initBmvPlayer(wrapper) {
| |
| var $wrapper = $(wrapper);
| |
|
| |
| var songName = $wrapper.data('song-name');
| |
| var rawDifficulties = $wrapper.data('difficulties');
| |
|
| |
| var $difficultyDiv = $wrapper.find('.difficulty-div');
| |
| var $ratioDiv = $wrapper.find('.ratio-div');
| |
| var $outputSpan = $wrapper.find('.output-span');
| |
|
| |
| var difficultyColors = {
| |
| "EZ": "#57E4C4", "HD": "#FDBA61", "IN": "#FE8661", "AT": "#4C364B"
| |
| };
| |
|
| |
| 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);
| |