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: Revertido |
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 */ |
|||
/* Ocultar links para páginas especiais de usuários não registrados */ |
/* Ocultar links para páginas especiais de usuários não registrados */ |
||
$( |
$(function () { |
||
// |
// Variável para controlar se já escondeu |
||
let searchHidden = false; |
|||
const updateVisibility = function() { |
|||
const isLoggedIn = mw.config.get( 'wgUserName' ) !== null; |
|||
// Função principal para ocultar elementos |
|||
const hideElementsForAnonymous = function() { |
|||
// Se já está logado, não fazer nada |
|||
if (mw.config.get('wgUserName') !== null) { |
|||
return; |
|||
} |
|||
// Se já escondeu, verificar se elementos reapareceram |
|||
if (!isLoggedIn) { |
|||
if (searchHidden) { |
|||
// Esconder elementos de busca |
|||
// Verificar se algum elemento de busca está visível |
|||
$('.vector-search-box, #p-search, #searchform').each(function() { |
|||
const searchVisible = $('#p-search').is(':visible') || |
|||
$( |
$('.vector-search-box').is(':visible') || |
||
$('#searchInput').is(':visible'); |
|||
if (!searchVisible) { |
|||
return; // Já está oculto, não precisa fazer nada |
|||
$('body').addClass('user-not-logged-in'); |
|||
} |
|||
// Mostrar elementos se estiver logado |
|||
$('.vector-search-box, #p-search, #searchform').show(); |
|||
$('body').removeClass('user-not-logged-in'); |
|||
} |
} |
||
// 1. Ocultar páginas especiais da navegação |
|||
$('#n-specialpages').hide(); |
|||
// 2. Ocultar TODAS as variações possíveis de busca |
|||
const searchSelectors = [ |
|||
'#p-search', |
|||
'#searchform', |
|||
'#searchInput', |
|||
'#simpleSearch', |
|||
'.mw-search', |
|||
'.vector-search-box', |
|||
'.vector-search-box-input', |
|||
'.vector-search-box-form', |
|||
'.vector-search-box-vue', |
|||
'.cdx-search-input', |
|||
'.cdx-text-input__input', |
|||
'[id*="search"]', |
|||
'[class*="search"]', |
|||
'input[name="search"]', |
|||
'.vector-header-end .vector-search-box', |
|||
'.vector-header-start .vector-search-box' |
|||
]; |
|||
// Aplicar a cada seletor |
|||
searchSelectors.forEach(selector => { |
|||
try { |
|||
$(selector).each(function() { |
|||
$(this).hide(); |
|||
$(this).css({ |
|||
'display': 'none !important', |
|||
'visibility': 'hidden !important' |
|||
}); |
|||
}); |
|||
} catch (e) { |
|||
console.log('Erro com seletor:', selector, e); |
|||
} |
|||
}); |
|||
// 3. Marcar como escondido |
|||
searchHidden = true; |
|||
// 4. Adicionar classe ao body para controle via CSS |
|||
$('body').addClass('anonymous-user'); |
|||
}; |
}; |
||
// Executar |
// Executar imediatamente |
||
hideElementsForAnonymous(); |
|||
// Executar novamente após carregamento completo |
|||
// Observar mudanças na configuração do MW (se houver) |
|||
$(window).on('load', hideElementsForAnonymous); |
|||
if (mw.config.values) { |
|||
Object.defineProperty(mw.config.values, 'wgUserName', { |
|||
// Executar em intervalos curtos inicialmente |
|||
set: function(value) { |
|||
let intervalCount = 0; |
|||
const initialInterval = setInterval(() => { |
|||
setTimeout(updateVisibility, 50); |
|||
hideElementsForAnonymous(); |
|||
intervalCount++; |
|||
if (intervalCount > 10) { // Parar após 10 execuções (5 segundos) |
|||
clearInterval(initialInterval); |
|||
} |
|||
}, 500); |
|||
// Observar mudanças no DOM de forma mais agressiva |
|||
const observer = new MutationObserver(function(mutations) { |
|||
let shouldHide = false; |
|||
mutations.forEach(function(mutation) { |
|||
if (mutation.addedNodes.length > 0) { |
|||
// Verificar se algum nó adicionado contém elementos de busca |
|||
$(mutation.addedNodes).each(function() { |
|||
if ($(this).find(searchSelectors.join(',')).length > 0 || |
|||
$(this).is(searchSelectors.join(','))) { |
|||
shouldHide = true; |
|||
} |
|||
}); |
|||
} |
} |
||
}); |
}); |
||
if (shouldHide) { |
|||
hideElementsForAnonymous(); |
|||
} |
|||
}); |
|||
observer.observe(document.body, { |
|||
// Executar periodicamente por segurança |
|||
childList: true, |
|||
setInterval(updateVisibility, 1000); |
|||
subtree: true, |
|||
attributes: true, |
|||
attributeFilter: ['style', 'class', 'id'] |
|||
}); |
|||
// Monitorar cliques em qualquer link, especialmente "ENTRAR" |
|||
// Executar em eventos específicos |
|||
$(document).on('click', ' |
$(document).on('click', 'a', function(e) { |
||
const href = $(this).attr('href') || ''; |
|||
setTimeout(updateVisibility, 500); |
|||
if (href.includes('Special:UserLogin') || |
|||
href.includes('title=Special:UserLogin') || |
|||
$(this).text().toLowerCase().includes('entrar') || |
|||
$(this).attr('id') === 'pt-login') { |
|||
// Antes do redirecionamento, garantir que elementos estejam ocultos |
|||
setTimeout(hideElementsForAnonymous, 100); |
|||
setTimeout(hideElementsForAnonymous, 500); |
|||
} |
|||
}); |
}); |
||
} ); |
|||
// Monitorar mudanças na URL (para quando clicar em ENTRAR) |
|||
let lastUrl = location.href; |
|||
new MutationObserver(() => { |
|||
const url = location.href; |
|||
if (url !== lastUrl) { |
|||
lastUrl = url; |
|||
if (url.includes('Special:UserLogin')) { |
|||
setTimeout(hideElementsForAnonymous, 100); |
|||
setTimeout(hideElementsForAnonymous, 500); |
|||
} |
|||
} |
|||
}).observe(document, { subtree: true, childList: true }); |
|||
}); |
|||
Edição das 08h39min 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 links para páginas especiais de usuários não registrados */
$(function () {
// Variável para controlar se já escondeu
let searchHidden = false;
// Função principal para ocultar elementos
const hideElementsForAnonymous = function() {
// Se já está logado, não fazer nada
if (mw.config.get('wgUserName') !== null) {
return;
}
// Se já escondeu, verificar se elementos reapareceram
if (searchHidden) {
// Verificar se algum elemento de busca está visível
const searchVisible = $('#p-search').is(':visible') ||
$('.vector-search-box').is(':visible') ||
$('#searchInput').is(':visible');
if (!searchVisible) {
return; // Já está oculto, não precisa fazer nada
}
}
// 1. Ocultar páginas especiais da navegação
$('#n-specialpages').hide();
// 2. Ocultar TODAS as variações possíveis de busca
const searchSelectors = [
'#p-search',
'#searchform',
'#searchInput',
'#simpleSearch',
'.mw-search',
'.vector-search-box',
'.vector-search-box-input',
'.vector-search-box-form',
'.vector-search-box-vue',
'.cdx-search-input',
'.cdx-text-input__input',
'[id*="search"]',
'[class*="search"]',
'input[name="search"]',
'.vector-header-end .vector-search-box',
'.vector-header-start .vector-search-box'
];
// Aplicar a cada seletor
searchSelectors.forEach(selector => {
try {
$(selector).each(function() {
$(this).hide();
$(this).css({
'display': 'none !important',
'visibility': 'hidden !important'
});
});
} catch (e) {
console.log('Erro com seletor:', selector, e);
}
});
// 3. Marcar como escondido
searchHidden = true;
// 4. Adicionar classe ao body para controle via CSS
$('body').addClass('anonymous-user');
};
// Executar imediatamente
hideElementsForAnonymous();
// Executar novamente após carregamento completo
$(window).on('load', hideElementsForAnonymous);
// Executar em intervalos curtos inicialmente
let intervalCount = 0;
const initialInterval = setInterval(() => {
hideElementsForAnonymous();
intervalCount++;
if (intervalCount > 10) { // Parar após 10 execuções (5 segundos)
clearInterval(initialInterval);
}
}, 500);
// Observar mudanças no DOM de forma mais agressiva
const observer = new MutationObserver(function(mutations) {
let shouldHide = false;
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length > 0) {
// Verificar se algum nó adicionado contém elementos de busca
$(mutation.addedNodes).each(function() {
if ($(this).find(searchSelectors.join(',')).length > 0 ||
$(this).is(searchSelectors.join(','))) {
shouldHide = true;
}
});
}
});
if (shouldHide) {
hideElementsForAnonymous();
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style', 'class', 'id']
});
// Monitorar cliques em qualquer link, especialmente "ENTRAR"
$(document).on('click', 'a', function(e) {
const href = $(this).attr('href') || '';
if (href.includes('Special:UserLogin') ||
href.includes('title=Special:UserLogin') ||
$(this).text().toLowerCase().includes('entrar') ||
$(this).attr('id') === 'pt-login') {
// Antes do redirecionamento, garantir que elementos estejam ocultos
setTimeout(hideElementsForAnonymous, 100);
setTimeout(hideElementsForAnonymous, 500);
}
});
// Monitorar mudanças na URL (para quando clicar em ENTRAR)
let lastUrl = location.href;
new MutationObserver(() => {
const url = location.href;
if (url !== lastUrl) {
lastUrl = url;
if (url.includes('Special:UserLogin')) {
setTimeout(hideElementsForAnonymous, 100);
setTimeout(hideElementsForAnonymous, 500);
}
}
}).observe(document, { subtree: true, childList: true });
});