MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
小 |
|||
| 第63行: | 第63行: | ||
$(MetaCaixaInit); | $(MetaCaixaInit); | ||
//BMV模板script | //BMV模板script | ||
(function(mw, $) { | (function(mw, $) { | ||
'use strict'; | 'use strict'; | ||
| 第69行: | 第69行: | ||
function initBmvPlayer(wrapper) { | function initBmvPlayer(wrapper) { | ||
var $wrapper = $(wrapper); | var $wrapper = $(wrapper); | ||
var songName = $wrapper.data('song-name'); | var songName = $wrapper.data('song-name'); | ||
var rawDifficulties = $wrapper.data('difficulties'); | var rawDifficulties = $wrapper.data('difficulties'); | ||
var $difficultyDiv = $wrapper.find('.difficulty-div'); | var $difficultyDiv = $wrapper.find('.difficulty-div'); | ||
var $ratioDiv = $wrapper.find('.ratio-div'); | var $ratioDiv = $wrapper.find('.ratio-div'); | ||
var $outputSpan = $wrapper.find('.output-span'); | 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 difficulty format for item: ' + item); } return (match[1].toUpperCase() + ' ' + match[2]); }); } catch (e) { console.error("Error parsing difficulties:", input, e); return null; } } | 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 difficulty format for item: ' + item); | |||
} | |||
return (match[1].toUpperCase() + ' ' + match[2]); | |||
}); | |||
} catch (e) { | |||
console.error("Error parsing difficulties:", input, e); | |||
return null; | |||
} | |||
} | |||
var difficultyStates = parseDifficulties(rawDifficulties); | 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; } | |||
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)); | $difficultyDiv.attr('data-states', JSON.stringify(difficultyStates)); | ||
function updateOutput() { | |||
var difficulty = $difficultyDiv.text().split(' ')[0]; | |||
var ratio = $ratioDiv.text().replace(':', '-'); | |||
var processedSongName = songName.replace(/[\\/:\*\?"<>\|]/g, '-'); | |||
var encodedSongName = encodeURIComponent(processedSongName); | |||
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(); | |||
})(); | |||
} | |||
} | } | ||
| 第177行: | 第165行: | ||
$(this).removeClass('bmv-player-uninitialized'); | $(this).removeClass('bmv-player-uninitialized'); | ||
}); | }); | ||
}); | }); | ||
})(mediaWiki, jQuery); | })(mediaWiki, jQuery); | ||
2025年11月29日 (六) 22:13的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* JavaScript used for https://zh.wikipedia.org/wiki/MediaWiki:Common.js : */
/** metaBox
*
* Funcionament de la Plantilla:Metacaixa
* Implementat per: Usuari:Peleguer.
* Actualitzat per Joanjoc seguint les indicacions d'en Martorell
*/
document.querySelector('.mw-logo-wordmark').textContent=''
function MetaCaixaInit() {
// S'executa al carregar-se la pàgina, si hi ha metacaixes,
// s'assignen els esdeveniments als botons
//alert("MetaCaixaInit");
var i = 0; // Inicialitzem comptador de caixes
for (i = 0; i <= 9; i++) {
var vMc = document.getElementById("mc" + i);
if (!vMc) break;
//alert("MetaCaixaInit, trobada Metacaixa mc"+i);
var j = 1; // Inicialitzem comptador de botons dins de la caixa
var vPsIni = 0; // Pestanya visible inicial
for (j = 1; j <= 9; j++) {
var vBt = document.getElementById("mc" + i + "bt" + j);
if (!vBt) break;
//alert("MetaCaixaInit, trobat botó mc"+i+"bt"+j);
vBt.onclick = MetaCaixaMostraPestanya; // A cada botó assignem l'esdeveniment onclick
//alert (vBt.className);
if (vBt.className == "mcBotoSel") vPsIni = j; // Si tenim un botó seleccionat, en guardem l'index
}
//alert ("mc="+i+", ps="+j+", psini="+vPsIni );
if (vPsIni === 0) { // Si no tenim cap botó seleccionat, n'agafem un aleatòriament
vPsIni = 1 + Math.floor((j - 1) * Math.random());
//alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
document.getElementById("mc" + i + "ps" + vPsIni).style.display = "block";
document.getElementById("mc" + i + "ps" + vPsIni).style.visibility = "visible";
document.getElementById("mc" + i + "bt" + vPsIni).className = "mcBotoSel";
}
}
}
function MetaCaixaMostraPestanya() {
// S'executa al clicar una pestanya,
// aquella es fa visible i les altres s'oculten
var vMcNom = this.id.substr(0, 3); // A partir del nom del botó, deduïm el nom de la caixa
var vIndex = this.id.substr(5, 1); // I l'index
var i = 1;
for (i = 1; i <= 9; i++) { // busquem totes les pestanyes d'aquella caixa
//alert(vMcNom+"ps"+i);
var vPsElem = document.getElementById(vMcNom + "ps" + i);
if (!vPsElem) break;
if (vIndex == i) { // Si és la pestanya bona la mostrem i canviem la classe de botó
vPsElem.style.display = "block";
vPsElem.style.visibility = "visible";
document.getElementById(vMcNom + "bt" + i).className = "mcBotoSel";
} else { // Sinó, l'ocultem i canviem la classe de botó
vPsElem.style.display = "none";
vPsElem.style.visibility = "hidden";
document.getElementById(vMcNom + "bt" + i).className = "mcBoto";
}
}
return false; // evitem la recàrrega de la pàgina
}
$(MetaCaixaInit);
//BMV模板script
(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 difficulty format for item: ' + item);
}
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 processedSongName = songName.replace(/[\\/:\*\?"<>\|]/g, '-');
var encodedSongName = encodeURIComponent(processedSongName);
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) {
// 初始化 BMV 播放器
$content.find('.bmv-player-uninitialized').each(function() {
initBmvPlayer(this);
$(this).removeClass('bmv-player-uninitialized');
});
});
})(mediaWiki, jQuery);