Difference between revisions of "MediaWiki:Common.js"

From XilePK - Ragnarok Online Server
Jump to navigation Jump to search
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
  
$(document).ready(function() {
+
// Função simples para copiar texto
  // Função para processar as tags warp
+
function copyToClipboard(text) {
  function processWarpTags() {
+
  var temp = document.createElement('textarea');
    console.log("Processando tags warp...");
+
  temp.value = text;
   
+
  document.body.appendChild(temp);
    // Obtém o conteúdo da página
+
  temp.select();
    var content = $('.mw-parser-output').html();
+
  document.execCommand('copy');
    if (!content) return;
+
  document.body.removeChild(temp);
   
+
}
    // Padrão mais flexível para capturar a tag
+
 
    var pattern = /<v\s+(.*?)\s+<c\s+(@warp.*?)\s+<c>\s+v>/gi;
+
// Adiciona evento de clique para elementos com a classe warp-copy
   
+
$(document).on('click', '.warp-copy', function() {
    // Substitui o padrão por um span clicável
+
  copyToClipboard($(this).data('copy'));
    var newContent = content.replace(pattern, function(match, visible, copyText) {
 
      console.log("Match encontrado:", visible, copyText);
 
      return '<span class="warp-copy" data-copy="' + copyText.trim() +
 
            '" style="color:#0066cc;cursor:pointer;border-bottom:1px dotted #0066cc;">' +
 
            visible.trim() + '</span>';
 
    });
 
   
 
    // Atualiza o conteúdo se houve mudanças
 
    if (content !== newContent) {
 
      console.log("Conteúdo atualizado");
 
      $('.mw-parser-output').html(newContent);
 
    }
 
  }
 
 
    
 
    
   // Adiciona o handler de clique
+
   // Feedback visual
  $(document).on('click', '.warp-copy', function() {
+
  var origColor = $(this).css('color');
    var text = $(this).attr('data-copy');
+
  $(this).css('color', 'green');
    console.log("Copiando:", text);
+
  var self = this;
   
+
  setTimeout(function() {
    var temp = document.createElement('textarea');
+
    $(self).css('color', origColor);
    temp.value = text;
+
   }, 500);
    document.body.appendChild(temp);
 
    temp.select();
 
    document.execCommand('copy');
 
    document.body.removeChild(temp);
 
   
 
    // Feedback visual
 
    var origColor = $(this).css('color');
 
    $(this).css('color', 'green');
 
    var self = this;
 
    setTimeout(function() {
 
      $(self).css('color', origColor);
 
    }, 500);
 
   });
 
 
 
  // Executa a função após o carregamento da página
 
  setTimeout(processWarpTags, 500);
 
 
 
  // Também executa quando o conteúdo é atualizado via AJAX
 
  mw.hook('wikipage.content').add(function() {
 
    setTimeout(processWarpTags, 500);
 
  });
 
 
});
 
});

Revision as of 12:15, 11 April 2025

/* Any JavaScript here will be loaded for all users on every page load. */

// Função simples para copiar texto
function copyToClipboard(text) {
  var temp = document.createElement('textarea');
  temp.value = text;
  document.body.appendChild(temp);
  temp.select();
  document.execCommand('copy');
  document.body.removeChild(temp);
}

// Adiciona evento de clique para elementos com a classe warp-copy
$(document).on('click', '.warp-copy', function() {
  copyToClipboard($(this).data('copy'));
  
  // Feedback visual
  var origColor = $(this).css('color');
  $(this).css('color', 'green');
  var self = this;
  setTimeout(function() {
    $(self).css('color', origColor);
  }, 500);
});