|
|
| (One intermediate revision by the same user not shown) |
| Line 1: |
Line 1: |
| // Override the page the user is redirected to when clicking the logo
| |
| // based only on ?uselang=fr|en|es in the URL, then remember it.
| |
| (function () {
| |
| const ALLOWED_LANGS = [ 'fr', 'en', 'es' ];
| |
| const STORAGE_KEY = 'emushpedia_lang';
| |
|
| |
|
| function getLangFromUrl() {
| |
| const params = new URLSearchParams( window.location.search );
| |
| const uselang = params.get( 'uselang' );
| |
| return ALLOWED_LANGS.includes( uselang ) ? uselang : null;
| |
| }
| |
|
| |
| function getStoredLang() {
| |
| const stored = localStorage.getItem( STORAGE_KEY );
| |
| return ALLOWED_LANGS.includes( stored ) ? stored : null;
| |
| }
| |
|
| |
| function saveLang( lang ) {
| |
| if ( ALLOWED_LANGS.includes( lang ) ) {
| |
| localStorage.setItem( STORAGE_KEY, lang );
| |
| }
| |
| }
| |
|
| |
| function getLang() {
| |
| const urlLang = getLangFromUrl();
| |
|
| |
| if ( urlLang ) {
| |
| saveLang( urlLang );
| |
| return urlLang;
| |
| }
| |
|
| |
| return getStoredLang() || 'en';
| |
| }
| |
|
| |
| function getHomeTitle( lang ) {
| |
| if ( lang === 'fr' ) {
| |
| return 'Accueil';
| |
| }
| |
| if ( lang === 'es' ) {
| |
| return 'Inicio';
| |
| }
| |
| return 'Home';
| |
| }
| |
|
| |
| function rewriteMainLinks() {
| |
| const lang = getLang();
| |
| const target = getHomeTitle( lang );
| |
| const url = mw.util.getUrl( target, { uselang: lang } );
| |
|
| |
| // Logo
| |
| document.querySelectorAll( 'a.mw-wiki-logo, a.mw-logo' ).forEach( function ( a ) {
| |
| a.href = url;
| |
| a.title = target;
| |
| } );
| |
|
| |
| // Sidebar main page links
| |
| document.querySelectorAll( '#n-n-lang-mainpage a, a[accesskey="z"]' ).forEach( function ( a ) {
| |
| a.href = url;
| |
| a.title = target;
| |
| } );
| |
| }
| |
|
| |
| mw.loader.using( [ 'mediawiki.util' ] ).then( rewriteMainLinks );
| |
| }());
| |