MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Conteúdo deletado Conteúdo adicionado
Sem resumo de edição Etiqueta: Reversão manual |
Sem resumo de edição Etiqueta: Revertido |
||
| Linha 1: | Linha 1: | ||
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */ |
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */ |
||
/* Ocultar |
/* Ocultar busca e páginas especiais para usuários não registrados - Vector Legado */ |
||
$(function () { |
|||
if ( mw.config.get( 'wgUserName' ) === null ) { |
|||
// Verificar se é usuário anônimo |
|||
$( function () { |
|||
if (mw.config.get('wgUserName') === null) { |
|||
// Exemplo: Oculta o link "Páginas especiais" na navegação lateral (Vector skin) |
|||
// Função para esconder elementos específicos do Vector Legado |
|||
const hideElementsVectorLegacy = function() { |
|||
// Se você quiser ocultar um link específico, como "Mudanças recentes" (RecentChanges) |
|||
console.log('Executando hideElementsVectorLegacy'); |
|||
// $( '#n-recentchanges' ).hide(); |
|||
// |
// 1. Ocultar PÁGINAS ESPECIAIS do menu lateral |
||
$('#n-specialpages').hide(); |
|||
// 2. Ocultar a CAIXA DE BUSCA (Vector Legado específico) |
|||
// O container principal da busca |
|||
$('#p-search').hide(); |
|||
// O formulário de busca |
|||
$('#searchform').hide(); |
|||
// Vector 2022 (barra de busca no topo) |
|||
$( '.vector-search-box, .vector-search-box-input, .vector-search-box-form' ).hide(); |
|||
// O input da busca |
|||
$('#searchInput').hide(); |
|||
// Fallback: se algum elemento for re-inserido dinamicamente, garante ocultação |
|||
// (ex.: carregamentos tardios ou gadgets que recriam a busca) |
|||
// O botão de busca |
|||
$( |
$('#searchButton, .searchButton').hide(); |
||
$( '.vector-search-box, .vector-search-box-input, .vector-search-box-form' ).hide(); |
|||
// O container "Busca" no menu lateral |
|||
$('#p-search h5').parent().hide(); // Esconde o título "Busca" e seu conteúdo |
|||
// 3. Ocultar outros elementos de busca que podem aparecer |
|||
$('.portal#p-search').hide(); // Portal de busca completo |
|||
$('div.vectorMenu#p-search').hide(); // Menu de busca |
|||
$('#simpleSearch').hide(); // Busca simples |
|||
// 4. Garantir que fique oculto com CSS inline |
|||
$('#p-search, #searchform, #searchInput').css({ |
|||
'display': 'none !important', |
|||
'visibility': 'hidden !important', |
|||
'width': '0 !important', |
|||
'height': '0 !important', |
|||
'opacity': '0 !important', |
|||
'position': 'absolute !important', |
|||
'left': '-9999px !important' |
|||
}); |
|||
// 5. Remover qualquer evento de foco/clique na busca |
|||
$('#searchInput').off('focus click keydown'); |
|||
$('#searchButton').off('click'); |
|||
// 6. Adicionar classe ao body para controle CSS |
|||
$('body').addClass('vector-legacy-anonymous'); |
|||
}; |
}; |
||
// Executar imediatamente |
|||
// Observa mudanças no DOM por alguns segundos para pegar inserções tardias |
|||
hideElementsVectorLegacy(); |
|||
const observer = new MutationObserver( hideSearch ); |
|||
observer.observe( document.body, { childList: true, subtree: true } ); |
|||
// Executar quando o DOM estiver completamente pronto |
|||
setTimeout( () => observer.disconnect(), 5000 ); |
|||
$(window).on('load', function() { |
|||
} ); |
|||
hideElementsVectorLegacy(); |
|||
} |
|||
// Executar novamente após 500ms para garantir |
|||
setTimeout(hideElementsVectorLegacy, 500); |
|||
}); |
|||
// Executar várias vezes nos primeiros segundos |
|||
let executionCount = 0; |
|||
const quickInterval = setInterval(function() { |
|||
hideElementsVectorLegacy(); |
|||
executionCount++; |
|||
if (executionCount >= 8) { // 4 segundos (8 x 500ms) |
|||
clearInterval(quickInterval); |
|||
} |
|||
}, 500); |
|||
// Executar periodicamente (a cada 2 segundos) por segurança |
|||
setInterval(hideElementsVectorLegacy, 2000); |
|||
// Observador de mutação específico para Vector Legado |
|||
const observer = new MutationObserver(function(mutations) { |
|||
let needsUpdate = false; |
|||
mutations.forEach(function(mutation) { |
|||
// Verificar se elementos relacionados à busca foram adicionados/modificados |
|||
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { |
|||
$(mutation.addedNodes).each(function() { |
|||
const $node = $(this); |
|||
if ($node.is('#p-search, #searchform, #searchInput') || |
|||
$node.find('#p-search, #searchform, #searchInput').length > 0 || |
|||
$node.hasClass('vectorMenu') && $node.attr('id') === 'p-search') { |
|||
needsUpdate = true; |
|||
} |
|||
}); |
|||
} |
|||
// Verificar mudanças de estilo/visibilidade |
|||
if (mutation.type === 'attributes' && |
|||
(mutation.attributeName === 'style' || mutation.attributeName === 'class')) { |
|||
const $target = $(mutation.target); |
|||
if ($target.is('#p-search, #searchform, #searchInput') && |
|||
($target.is(':visible') || $target.css('display') !== 'none')) { |
|||
needsUpdate = true; |
|||
} |
|||
} |
|||
}); |
|||
if (needsUpdate) { |
|||
hideElementsVectorLegacy(); |
|||
} |
|||
}); |
|||
// Observar o elemento #mw-panel (menu lateral do Vector Legado) |
|||
const leftPanel = document.getElementById('mw-panel'); |
|||
if (leftPanel) { |
|||
observer.observe(leftPanel, { |
|||
childList: true, |
|||
subtree: true, |
|||
attributes: true, |
|||
attributeFilter: ['style', 'class'] |
|||
}); |
|||
} |
|||
// Também observar o corpo principal |
|||
observer.observe(document.body, { |
|||
childList: true, |
|||
subtree: false, |
|||
attributes: false |
|||
}); |
|||
// Interceptar clique no botão "ENTRAR" (específico Vector Legado) |
|||
$(document).on('click', function(e) { |
|||
const $target = $(e.target); |
|||
const $link = $target.closest('a'); |
|||
if ($link.length) { |
|||
const href = $link.attr('href') || ''; |
|||
const text = $link.text().toLowerCase(); |
|||
const id = $link.attr('id') || ''; |
|||
// Verificar se é o link de login do Vector Legado |
|||
if (href.includes('Special:UserLogin') || |
|||
href.includes('title=Special:UserLogin') || |
|||
text.includes('entrar') || |
|||
text.includes('login') || |
|||
id === 'pt-login' || |
|||
$link.parent().attr('id') === 'pt-login') { |
|||
console.log('Detectado clique em ENTRAR - escondendo elementos'); |
|||
// Executar múltiplas vezes para garantir durante o redirecionamento |
|||
for (let i = 1; i <= 5; i++) { |
|||
setTimeout(hideElementsVectorLegacy, i * 100); |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
// Monitorar mudanças na hash/URL |
|||
let lastHref = location.href; |
|||
setInterval(function() { |
|||
if (location.href !== lastHref) { |
|||
lastHref = location.href; |
|||
if (location.href.includes('Special:UserLogin')) { |
|||
hideElementsVectorLegacy(); |
|||
} |
|||
} |
|||
}, 100); |
|||
} else { |
|||
// Se estiver logado, REMOVER a classe anônima se existir |
|||
$('body').removeClass('vector-legacy-anonymous'); |
|||
} |
|||
}); |
|||
Edição das 08h49min de 16 de janeiro de 2026
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */
/* Ocultar busca e páginas especiais para usuários não registrados - Vector Legado */
$(function () {
// Verificar se é usuário anônimo
if (mw.config.get('wgUserName') === null) {
// Função para esconder elementos específicos do Vector Legado
const hideElementsVectorLegacy = function() {
console.log('Executando hideElementsVectorLegacy');
// 1. Ocultar PÁGINAS ESPECIAIS do menu lateral
$('#n-specialpages').hide();
// 2. Ocultar a CAIXA DE BUSCA (Vector Legado específico)
// O container principal da busca
$('#p-search').hide();
// O formulário de busca
$('#searchform').hide();
// O input da busca
$('#searchInput').hide();
// O botão de busca
$('#searchButton, .searchButton').hide();
// O container "Busca" no menu lateral
$('#p-search h5').parent().hide(); // Esconde o título "Busca" e seu conteúdo
// 3. Ocultar outros elementos de busca que podem aparecer
$('.portal#p-search').hide(); // Portal de busca completo
$('div.vectorMenu#p-search').hide(); // Menu de busca
$('#simpleSearch').hide(); // Busca simples
// 4. Garantir que fique oculto com CSS inline
$('#p-search, #searchform, #searchInput').css({
'display': 'none !important',
'visibility': 'hidden !important',
'width': '0 !important',
'height': '0 !important',
'opacity': '0 !important',
'position': 'absolute !important',
'left': '-9999px !important'
});
// 5. Remover qualquer evento de foco/clique na busca
$('#searchInput').off('focus click keydown');
$('#searchButton').off('click');
// 6. Adicionar classe ao body para controle CSS
$('body').addClass('vector-legacy-anonymous');
};
// Executar imediatamente
hideElementsVectorLegacy();
// Executar quando o DOM estiver completamente pronto
$(window).on('load', function() {
hideElementsVectorLegacy();
// Executar novamente após 500ms para garantir
setTimeout(hideElementsVectorLegacy, 500);
});
// Executar várias vezes nos primeiros segundos
let executionCount = 0;
const quickInterval = setInterval(function() {
hideElementsVectorLegacy();
executionCount++;
if (executionCount >= 8) { // 4 segundos (8 x 500ms)
clearInterval(quickInterval);
}
}, 500);
// Executar periodicamente (a cada 2 segundos) por segurança
setInterval(hideElementsVectorLegacy, 2000);
// Observador de mutação específico para Vector Legado
const observer = new MutationObserver(function(mutations) {
let needsUpdate = false;
mutations.forEach(function(mutation) {
// Verificar se elementos relacionados à busca foram adicionados/modificados
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
$(mutation.addedNodes).each(function() {
const $node = $(this);
if ($node.is('#p-search, #searchform, #searchInput') ||
$node.find('#p-search, #searchform, #searchInput').length > 0 ||
$node.hasClass('vectorMenu') && $node.attr('id') === 'p-search') {
needsUpdate = true;
}
});
}
// Verificar mudanças de estilo/visibilidade
if (mutation.type === 'attributes' &&
(mutation.attributeName === 'style' || mutation.attributeName === 'class')) {
const $target = $(mutation.target);
if ($target.is('#p-search, #searchform, #searchInput') &&
($target.is(':visible') || $target.css('display') !== 'none')) {
needsUpdate = true;
}
}
});
if (needsUpdate) {
hideElementsVectorLegacy();
}
});
// Observar o elemento #mw-panel (menu lateral do Vector Legado)
const leftPanel = document.getElementById('mw-panel');
if (leftPanel) {
observer.observe(leftPanel, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style', 'class']
});
}
// Também observar o corpo principal
observer.observe(document.body, {
childList: true,
subtree: false,
attributes: false
});
// Interceptar clique no botão "ENTRAR" (específico Vector Legado)
$(document).on('click', function(e) {
const $target = $(e.target);
const $link = $target.closest('a');
if ($link.length) {
const href = $link.attr('href') || '';
const text = $link.text().toLowerCase();
const id = $link.attr('id') || '';
// Verificar se é o link de login do Vector Legado
if (href.includes('Special:UserLogin') ||
href.includes('title=Special:UserLogin') ||
text.includes('entrar') ||
text.includes('login') ||
id === 'pt-login' ||
$link.parent().attr('id') === 'pt-login') {
console.log('Detectado clique em ENTRAR - escondendo elementos');
// Executar múltiplas vezes para garantir durante o redirecionamento
for (let i = 1; i <= 5; i++) {
setTimeout(hideElementsVectorLegacy, i * 100);
}
}
}
});
// Monitorar mudanças na hash/URL
let lastHref = location.href;
setInterval(function() {
if (location.href !== lastHref) {
lastHref = location.href;
if (location.href.includes('Special:UserLogin')) {
hideElementsVectorLegacy();
}
}
}, 100);
} else {
// Se estiver logado, REMOVER a classe anônima se existir
$('body').removeClass('vector-legacy-anonymous');
}
});