Jump to content

MediaWiki:Common.js: Difference between revisions

From EthernalRO Wiki
Created page with "Any JavaScript here will be loaded for all users on every page load.: function copiarNavi(mapa, y, x) { const texto = `/navi ${mapa},${y},${x}`; if (navigator.clipboard) { navigator.clipboard.writeText(texto).then(() => { mw.notify(`Copiado: ${texto}`); }); } else { // fallback antigo const temp = document.createElement("textarea"); temp.value = texto; document.body.appendChild(temp); t..."
 
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Script para copiar navegação */
function copiarNavi(mapa, y, x) {
$(function() {
     const texto = `/navi ${mapa},${y},${x}`;
     // Usa 'body' para garantir que funcione mesmo em elementos carregados dinamicamente
 
    $('body').on('click', '.navi-link', function(e) {
    if (navigator.clipboard) {
        e.preventDefault();
         navigator.clipboard.writeText(texto).then(() => {
        var $this = $(this);
            mw.notify(`Copiado: ${texto}`);
        var map = $this.data('map');
         });
         var x = $this.data('x');
    } else {
        var y = $this.data('y');
         // fallback antigo
       
         const temp = document.createElement("textarea");
        // Remove espaços extras caso existam
         temp.value = texto;
        if(map) map = map.trim();
        document.body.appendChild(temp);
          
         temp.select();
        var command = '/navi ' + map + ' ' + x + '/' + y;
       
         // Cria elemento invisível para copiar
         var $temp = $("<input>");
         $("body").append($temp);
         $temp.val(command).select();
         document.execCommand("copy");
         document.execCommand("copy");
         document.body.removeChild(temp);
         $temp.remove();
         mw.notify(`Copiado: ${texto}`);
       
     }
        // Feedback visual
}
        var $msg = $this.find('.navi-msg');
         $msg.show().fadeOut(2000);
     });
});

Latest revision as of 23:09, 26 January 2026

/* Script para copiar navegação */
$(function() {
    // Usa 'body' para garantir que funcione mesmo em elementos carregados dinamicamente
    $('body').on('click', '.navi-link', function(e) {
        e.preventDefault();
        var $this = $(this);
        var map = $this.data('map');
        var x = $this.data('x');
        var y = $this.data('y');
        
        // Remove espaços extras caso existam
        if(map) map = map.trim();
        
        var command = '/navi ' + map + ' ' + x + '/' + y;
        
        // Cria elemento invisível para copiar
        var $temp = $("<input>");
        $("body").append($temp);
        $temp.val(command).select();
        document.execCommand("copy");
        $temp.remove();
        
        // Feedback visual
        var $msg = $this.find('.navi-msg');
        $msg.show().fadeOut(2000);
    });
});