|
|
| (未显示同一用户的7个中间版本) |
| 第1行: |
第1行: |
| mw.loader.using(['mediawiki.util', 'jquery']).done(function() {
| | /* PWA安装测试 */ |
| $(function() {
| | (function() { |
| $('.bmv-container').each(function() { | | var btn = document.getElementById('pwa-test-btn'); |
| const container = $(this);
| | var savedPrompt = null; |
| const songName = container.data('song-name');
| | window.addEventListener('beforeinstallprompt', function(e) { |
| const rawDifficulties = container.data('difficulties'); | | e.preventDefault(); |
| | | savedPrompt = e; |
| // 在当前容器内查找元素 | | if (btn) btn.style.display = 'block'; |
| const difficultyDiv = container.find('.bmv-difficulty-btn'); | | }); |
| const ratioDiv = container.find('.bmv-ratio-btn');
| | if (btn) { |
| const outputSpan = container.find('.bmv-output');
| | btn.addEventListener('click', function() { |
| | | if (savedPrompt) { |
| // 难度颜色映射
| | savedPrompt.prompt(); |
| const difficultyColors = {
| | savedPrompt = null; |
| "EZ": "#57E4C4",
| | } else { |
| "HD": "#FDBA61",
| | alert('暂时无法安装(可能已安装或不支持)'); |
| "IN": "#FE8661",
| |
| "AT": "#4C364B"
| |
| };
| |
| | |
| // 解析并设置难度数据
| |
| function parseDifficulties(input) {
| |
| if (!input || typeof input !== 'string') return null;
| |
| try {
| |
| return input.split(',').map(item => {
| |
| const match = item.trim().match(/^([A-Za-z]+)\s*(\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;
| |
| } | | } |
| } | | }); |
| | | } |
| const difficultyStates = parseDifficulties(rawDifficulties);
| | })(); |
| | |
| // 检查参数是否有效
| |
| if (!songName || !difficultyStates || difficultyStates.length === 0) {
| |
| // 在容器内显示错误信息,而不是替换整个表格
| |
| container.css('text-align', 'center').html('<div style="color:red; padding:20px; font-weight:bold;">模板错误:缺少或无效的 songName/difficulties 参数。</div>');
| |
| return;
| |
| }
| |
| difficultyDiv.attr('data-states', JSON.stringify(difficultyStates));
| |
|
| |
| // 更新视频输出
| |
| function updateOutput() {
| |
| const difficulty = difficultyDiv.text().split(' ')[0];
| |
| const ratio = ratioDiv.text().replace(':', '-');
| |
| const encodedSongName = encodeURIComponent(songName);
| |
| const videoUrl = `https://pan.rizwiki.cn/d/${ratio}_${encodedSongName}_${difficulty}.mp4`;
| |
|
| |
| const videoElement = $('<video>', {
| |
| class: 'html5media-video',
| |
| src: videoUrl,
| |
| controls: true,
| |
| preload: 'metadata',
| |
| loading: 'lazy',
| |
| style: 'height:100%; width:100%; object-fit:contain;'
| |
| });
| |
| outputSpan.html(videoElement);
| |
| }
| |
| | |
| // 切换难度
| |
| function cycleDifficulty() {
| |
| const states = JSON.parse(difficultyDiv.attr('data-states'));
| |
| let current = parseInt(difficultyDiv.attr('data-current'), 10);
| |
| current = (current + 1) % states.length;
| |
| | |
| const nextState = states[current];
| |
| const difficultyType = nextState.split(' ')[0];
| |
| const color = difficultyColors[difficultyType] || '#FFFFFF';
| |
| | |
| difficultyDiv.text(nextState).attr('data-current', current);
| |
| difficultyDiv.parent().css('background-color', color); // 注意这里是父元素td
| |
| updateOutput();
| |
| }
| |
| | |
| // 切换宽高比
| |
| function cycleRatio() {
| |
| const states = JSON.parse(ratioDiv.attr('data-states'));
| |
| let current = parseInt(ratioDiv.attr('data-current'), 10);
| |
| current = (current + 1) % states.length;
| |
| | |
| ratioDiv.text(states[current]).attr('data-current', current);
| |
| updateOutput();
| |
| }
| |
|
| |
| // 绑定事件
| |
| difficultyDiv.on('click', cycleDifficulty);
| |
| ratioDiv.parent().on('click', cycleRatio);
| |
| | |
| // 初始化
| |
| function initialize() {
| |
| const firstDiff = difficultyStates[0];
| |
| const diffType = firstDiff.split(' ')[0];
| |
|
| |
| difficultyDiv.text(firstDiff);
| |
| difficultyDiv.parent().css('background-color', difficultyColors[diffType]);
| |
|
| |
| updateOutput();
| |
| }
| |
| | |
| initialize();
| |
| });
| |
| });
| |
| });
| |
/* 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('暂时无法安装(可能已安装或不支持)');
}
});
}
})();