MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
console.log("[Language Menu] Script started"); | console.log("[Language Menu] Script started"); | ||
| Line 23: | Line 22: | ||
if (!currentLang) currentLang = 'en'; | if (!currentLang) currentLang = 'en'; | ||
// Labels | // Labels e links | ||
var labels = { | var labels = { | ||
'pt': 'Português', | 'pt': 'Português', | ||
| Line 30: | Line 29: | ||
}; | }; | ||
var links = {}; | |||
var links = { | |||
if (base === 'Main_Page' || base === 'Página_principal') { | if (base === 'Main_Page' || base === 'Página_principal') { | ||
links = { | links = { | ||
'pt': ' | 'pt': 'Página_principal/pt', | ||
'en': 'Main_Page', | 'en': 'Main_Page', // inglês é base | ||
'es': 'Main_Page/es' | 'es': 'Main_Page/es' | ||
}; | |||
} else { | |||
links = { | |||
'pt': base + '/pt', | |||
'en': base, // inglês é sem sufixo | |||
'es': base + '/es' | |||
}; | }; | ||
} | } | ||
| Line 54: | Line 52: | ||
el.textContent = labels[lang]; | el.textContent = labels[lang]; | ||
} else { | } else { | ||
el.innerHTML = '<a class="lang-menu-link" href="' + | el.innerHTML = '<a class="lang-menu-link" href="' + mw.util.getUrl(links[lang]) + '">' + labels[lang] + '</a>'; | ||
} | } | ||
} | } | ||
| Line 66: | Line 63: | ||
console.log("[Language Menu] Rewriting content links for:", currentLang); | console.log("[Language Menu] Rewriting content links for:", currentLang); | ||
document.querySelectorAll('#mw-content-text a[href^="/"]').forEach(function (link) { | //document.querySelectorAll('#mw-content-text a[href^="/"]').forEach(function (link) { | ||
document.querySelectorAll('a[href^="/doc/"]').forEach(function (link) { | |||
if (link.classList.contains('lang-menu-link')) return; // ignora menu de idiomas | if (link.classList.contains('lang-menu-link')) return; // ignora menu de idiomas | ||