Jump to content

MediaWiki:Common.js

From ATRONIA Wiki
Revision as of 09:34, 13 March 2026 by WikiManagement (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

/**
 * GOOGLE ANALYTICS
 * Injeção correta de script externo para evitar o erro de "Parse error"
 */
var gaScript = document.createElement('script');
gaScript.src = "https://www.googletagmanager.com/gtag/js?id=G-MX174P23PW";
gaScript.async = true;
document.head.appendChild(gaScript);

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-MX174P23PW');



/**
 * BOTÃO DE COPIAR (Copy Button)
 * Este script cria o botão de cópia em todos os blocos de código
 */
$(function() {
    // Procura os blocos gerados pela extensão SyntaxHighlight
    $('.mw-highlight').each(function() {
        var $block = $(this);
        
        // Evita botões duplicados
        if ($block.find('.copy-btn').length > 0) return;

        // Cria o botão com estilo azul
        var $button = $('<button>')
            .text('Copy')
            .addClass('copy-btn')
            .css({
                'position': 'absolute',
                'top': '10px',        // Mais espaço do topo
                'right': '10px',      // Mais espaço da direita
                'z-index': '100',
                'padding': '8px 16px', // Aumenta o tamanho (altura e largura)
                'background': '#28a745', // COR: Verde (podes mudar para #000 para preto, etc)
                'color': '#fff',
                'border': 'none',
                'border-radius': '8px', // CORNER RADIUS: Mais arredondado
                'cursor': 'pointer',
                'font-size': '14px',    // FONTE: Maior
                'font-weight': 'bold',
                'transition': '0.3s'    // Suaviza a mudança de cor
            });

        // Função para copiar o texto
        $button.on('click', function() {
            var text = $block.find('pre').text();
            
            navigator.clipboard.writeText(text).then(function() {
                $button.text('Copied!').css('background', '#00af89');
                setTimeout(function() {
                    $button.text('Copy').css('background', '#3366cc');
                }, 2000);
            }).catch(function(err) {
                console.error('Erro ao copiar: ', err);
            });
        });

        // Adiciona o botão ao bloco
        $block.css('position', 'relative').prepend($button);
    });
});