MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
/* | /* Botão de Copiar - Versão Final Estável */ | ||
$(function() { | $(function() { | ||
$('.mw-highlight').each(function() { | $('.mw-highlight').each(function() { | ||
var $block = $(this); | var $block = $(this); | ||
if ($block.find('.copy-btn').length > 0) return; | if ($block.find('.copy-btn').length > 0) return; | ||
var $button = $('<button>') | var $button = $('<button>') | ||
.text('Copy') | .text('Copy') | ||
| Line 35: | Line 28: | ||
.css({ | .css({ | ||
'position': 'absolute', | 'position': 'absolute', | ||
'top': '10px', | 'top': '10px', | ||
'right': '10px', | 'right': '10px', | ||
'z-index': '100', | 'z-index': '100', | ||
'padding': '8px | 'width': '80px', // Largura fixa para o botão não encolher/mudar de tamanho | ||
'background': '# | 'padding': '8px 0', // Padding vertical | ||
'color': '# | 'background': '#28a745', // Verde inicial | ||
'color': '#ffffff', // Texto sempre branco | |||
'border': 'none', | 'border': 'none', | ||
'border-radius': ' | 'border-radius': '12px', // Cantos bem arredondados | ||
'cursor': 'pointer', | 'cursor': 'pointer', | ||
'font-size': ' | 'font-size': '13px', | ||
'font-weight': 'bold', | 'font-weight': 'bold', | ||
'transition': '0.3s' | 'outline': 'none', // Remove contornos ao clicar | ||
'transition': 'background 0.3s ease' | |||
}); | }); | ||
// | // Forçar a cor do texto para não ficar roxo (importante para Wikis) | ||
$button.on('click', function() { | $button.css('color', '#ffffff !important'); | ||
// Estado: Rato por cima (Hover) | |||
$button.hover( | |||
function() { $(this).css('background', '#218838'); }, | |||
function() { | |||
// Volta para a cor correta dependendo se acabou de copiar ou não | |||
var bg = ($(this).text() === 'Copied!') ? '#007bff' : '#28a745'; | |||
$(this).css('background', bg); | |||
} | |||
); | |||
$button.on('click', function(e) { | |||
e.preventDefault(); // Impede qualquer comportamento de link da Wiki | |||
var text = $block.find('pre').text(); | var text = $block.find('pre').text(); | ||
navigator.clipboard.writeText(text).then(function() { | navigator.clipboard.writeText(text).then(function() { | ||
$button.text('Copied!').css('background', '# | // Estado: Sucesso (Copied!) | ||
$button.text('Copied!') | |||
.css({ | |||
'background': '#007bff', // Azul quando copiado | |||
'color': '#ffffff' | |||
}); | |||
setTimeout(function() { | setTimeout(function() { | ||
$button.text('Copy').css('background', '# | // Estado: Voltar ao normal | ||
$button.text('Copy') | |||
.css({ | |||
'background': '#28a745', | |||
'color': '#ffffff' | |||
}); | |||
}, 2000); | }, 2000); | ||
}); | }); | ||
}); | }); | ||
$block.css('position', 'relative').prepend($button); | $block.css('position', 'relative').prepend($button); | ||
}); | }); | ||
}); | }); | ||
Revision as of 09:41, 13 March 2026
/* 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 - Versão Final Estável */
$(function() {
$('.mw-highlight').each(function() {
var $block = $(this);
if ($block.find('.copy-btn').length > 0) return;
var $button = $('<button>')
.text('Copy')
.addClass('copy-btn')
.css({
'position': 'absolute',
'top': '10px',
'right': '10px',
'z-index': '100',
'width': '80px', // Largura fixa para o botão não encolher/mudar de tamanho
'padding': '8px 0', // Padding vertical
'background': '#28a745', // Verde inicial
'color': '#ffffff', // Texto sempre branco
'border': 'none',
'border-radius': '12px', // Cantos bem arredondados
'cursor': 'pointer',
'font-size': '13px',
'font-weight': 'bold',
'outline': 'none', // Remove contornos ao clicar
'transition': 'background 0.3s ease'
});
// Forçar a cor do texto para não ficar roxo (importante para Wikis)
$button.css('color', '#ffffff !important');
// Estado: Rato por cima (Hover)
$button.hover(
function() { $(this).css('background', '#218838'); },
function() {
// Volta para a cor correta dependendo se acabou de copiar ou não
var bg = ($(this).text() === 'Copied!') ? '#007bff' : '#28a745';
$(this).css('background', bg);
}
);
$button.on('click', function(e) {
e.preventDefault(); // Impede qualquer comportamento de link da Wiki
var text = $block.find('pre').text();
navigator.clipboard.writeText(text).then(function() {
// Estado: Sucesso (Copied!)
$button.text('Copied!')
.css({
'background': '#007bff', // Azul quando copiado
'color': '#ffffff'
});
setTimeout(function() {
// Estado: Voltar ao normal
$button.text('Copy')
.css({
'background': '#28a745',
'color': '#ffffff'
});
}, 2000);
});
});
$block.css('position', 'relative').prepend($button);
});
});