MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 1: | Linha 1: | ||
// | // Navi clicável - baseado na estrutura do bROWiki | ||
mw.loader.using('mediawiki.util').then(function () { | mw.loader.using('mediawiki.util').then(function () { | ||
// | function copiarTexto(text) { | ||
var | if (navigator.clipboard && navigator.clipboard.writeText) { | ||
return navigator.clipboard.writeText(text); | |||
var | } | ||
// fallback antigo | |||
return new Promise(function (resolve, reject) { | |||
try { | |||
var temp = document.createElement('textarea'); | |||
temp.value = text; | |||
document.body.appendChild(temp); | |||
temp.select(); | |||
document.execCommand('copy'); | |||
document.body.removeChild(temp); | |||
resolve(); | |||
} catch (e) { | |||
reject(e); | |||
} | |||
}); | |||
} | |||
function montarNavi(div) { | |||
var spans = div.getElementsByTagName('span'); | |||
if (spans.length < 3) return; | |||
var | var mapa = spans[0].textContent.trim(); | ||
var x = spans[1].textContent.trim(); | |||
var y = spans[2].textContent.trim(); | |||
// | // Limpa o conteúdo original | ||
while (div.firstChild) { | |||
div.removeChild(div.firstChild); | |||
mw.notify('Comando copiado: ' + | } | ||
} | |||
alert('Comando: ' + | // Texto clicável | ||
var texto = document.createElement('div'); | |||
texto.className = 'navi-copy-text'; | |||
texto.textContent = '(' + mapa + ' ' + x + ', ' + y + ')'; | |||
// Mensagem "copiado" | |||
var aviso = document.createElement('div'); | |||
aviso.className = 'navi-copied'; | |||
aviso.textContent = 'Comando copiado!'; | |||
aviso.style.display = 'none'; | |||
div.appendChild(texto); | |||
div.appendChild(aviso); | |||
texto.addEventListener('click', function () { | |||
var cmd = '/navi ' + mapa + ' ' + x + ' ' + y; | |||
copiarTexto(cmd).then(function () { | |||
aviso.style.display = 'inline'; | |||
setTimeout(function () { | |||
aviso.style.display = 'none'; | |||
}, 1500); | |||
if (mw && mw.notify) { | |||
mw.notify('Comando copiado: ' + cmd); | |||
} | |||
}).catch(function () { | |||
alert('Comando: ' + cmd); | |||
}); | }); | ||
} | }); | ||
} | |||
// Aplica em todos os .navi-copy da página | |||
document.querySelectorAll('.navi-copy').forEach(montarNavi); | |||
}); | }); | ||
Edição das 11h41min de 6 de novembro de 2025
// Navi clicável - baseado na estrutura do bROWiki
mw.loader.using('mediawiki.util').then(function () {
function copiarTexto(text) {
if (navigator.clipboard && navigator.clipboard.writeText) {
return navigator.clipboard.writeText(text);
}
// fallback antigo
return new Promise(function (resolve, reject) {
try {
var temp = document.createElement('textarea');
temp.value = text;
document.body.appendChild(temp);
temp.select();
document.execCommand('copy');
document.body.removeChild(temp);
resolve();
} catch (e) {
reject(e);
}
});
}
function montarNavi(div) {
var spans = div.getElementsByTagName('span');
if (spans.length < 3) return;
var mapa = spans[0].textContent.trim();
var x = spans[1].textContent.trim();
var y = spans[2].textContent.trim();
// Limpa o conteúdo original
while (div.firstChild) {
div.removeChild(div.firstChild);
}
// Texto clicável
var texto = document.createElement('div');
texto.className = 'navi-copy-text';
texto.textContent = '(' + mapa + ' ' + x + ', ' + y + ')';
// Mensagem "copiado"
var aviso = document.createElement('div');
aviso.className = 'navi-copied';
aviso.textContent = 'Comando copiado!';
aviso.style.display = 'none';
div.appendChild(texto);
div.appendChild(aviso);
texto.addEventListener('click', function () {
var cmd = '/navi ' + mapa + ' ' + x + ' ' + y;
copiarTexto(cmd).then(function () {
aviso.style.display = 'inline';
setTimeout(function () {
aviso.style.display = 'none';
}, 1500);
if (mw && mw.notify) {
mw.notify('Comando copiado: ' + cmd);
}
}).catch(function () {
alert('Comando: ' + cmd);
});
});
}
// Aplica em todos os .navi-copy da página
document.querySelectorAll('.navi-copy').forEach(montarNavi);
});