Jump to content

MediaWiki:Common.js

From ATRONIA Wiki
Revision as of 12:11, 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 Moderno com Ícone */
$(function() {
    $('.mw-highlight').each(function() {
        var $block = $(this);
        if ($block.find('.copy-btn').length > 0) return;

        // Ícone SVG de dois quadrados (estilo moderno)
        var copyIcon = '<svg fill="none" stroke-width="2.5" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height="1.2em" width="1.2em" xmlns="http://www.w3.org/2000/svg" style="margin-right: 8px; vertical-align: middle; stroke: white !important;">' +
                       '<rect x="9" y="9" width="13" height="13" rx="2" ry="2" style="stroke: white !important;"></rect>' +
                       '<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" style="stroke: white !important;"></path>' +
                       '</svg>';

        var $button = $('<button>')
            .html(copyIcon + '<span>Copy</span>')
            .addClass('copy-btn')
            .css({
                'position': 'absolute',
                'top': '10px',
                'right': '10px',
                'z-index': '100',
                'display': 'flex',
                'align-items': 'center',
                'padding': '6px 12px',
                'background': '#343a40', // Cor cinza escuro moderna
                'color': '#f8f9fa',      // Texto quase branco
                'border': '1px solid #495057',
                'border-radius': '6px',  // Cantos ligeiramente arredondados
                'cursor': 'pointer',
                'font-size': '12px',
                'font-family': 'sans-serif',
                'transition': 'all 0.2s ease'
            });

        // Efeito Hover (passar o rato)
        $button.hover(
            function() { $(this).css({'background': '#495057', 'border-color': '#6c757d'}); },
            function() { $(this).css({'background': '#343a40', 'border-color': '#495057'}); }
        );

        $button.on('click', function(e) {
            e.preventDefault();
            var text = $block.find('pre').text();
            
            navigator.clipboard.writeText(text).then(function() {
                // Muda o ícone e texto para "Copiado!"
                $button.find('span').text('Copied!');
                $button.css({'background': '#28a745', 'border-color': '#28a745'});

                setTimeout(function() {
                    $button.find('span').text('Copy');
                    $button.css({'background': '#343a40', 'border-color': '#495057'});
                }, 2000);
            });
        });

        $block.css('position', 'relative').prepend($button);
    });
});