1 881
edições
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 112: | Linha 112: | ||
mw.hook('wikipage.content').add(function($content) { | mw.hook('wikipage.content').add(function($content) { | ||
var isEnglish = mw.config.get('wgUserLanguage') === 'en' || mw.config.get('wgPageName'). | // Detecta se a página atual é /en ou se o idioma da interface do usuário está em inglês | ||
var isEnglish = mw.config.get('wgUserLanguage') === 'en' || mw.config.get('wgPageName').endsWith('/en'); | |||
if (isEnglish) { | if (isEnglish) { | ||
$content.find(' | // Pega todos os links da área de conteúdo | ||
$content.find('a').each(function() { | |||
var href = $(this).attr('href'); | var href = $(this).attr('href'); | ||
if (href && href.startsWith('/') && !href.includes('Special:') && !href.includes('Especial:') && !href.includes('?') && !href. | |||
// Só altera se for um link interno válido (começa com /, mas não com // que seria link externo) | |||
if (href && href.startsWith('/') && !href.startsWith('//') && !href.includes('Special:') && !href.includes('Especial:') && !href.includes('?')) { | |||
// Evita colocar /en repetido | |||
if (!href.endsWith('/en') && !href.includes('/en#')) { | |||
// Se o link tiver uma âncora (ex: /Charizard#Ataques), coloca o /en antes do # | |||
if (href.includes('#')) { | |||
$(this).attr('href', href.replace('#', '/en#')); | |||
} else { | |||
// Link normal | |||
$(this).attr('href', href + '/en'); | |||
} | |||
} | |||
} | } | ||
}); | }); | ||
} | } | ||
}); | }); | ||