MediaWiki:Common.js: differenze tra le versioni
Aspetto
Common.js v4: prepend mobile cookie nuke per stopMobileRedirect |
Common.js v5: rimuovo auto-redirect IT-RU bidirezionale (causava loop e ritorni in russo). Lascio solo mobile cookie nuke + cleanup cookie autolang residui. |
||
| Riga 1: | Riga 1: | ||
/* ============================================================ | /* ============================================================ | ||
* | * Common.js v5 — Wiki Methode Paret | ||
* ============================================================ | * ============================================================ | ||
* | * | ||
* | * PRINCIPIO: Non interferire con le scelte dell'utente. | ||
* ( | * URL decide il contenuto. L'icona globo (ULS) decide la UI. | ||
* Niente redirect automatici incrociati. | |||
* | * | ||
* | * Le uniche logiche attive: | ||
* 1. Pulizia cookie velenosi mobile (stopMobileRedirect, mf_useformat) | |||
* → permette a MobileFrontend di servire sempre Minerva su UA mobile | |||
* 2. Pulizia cookie autolang_set residuo da versioni precedenti | |||
* → toglie l'auto-redirect bidirezionale che disturbava | |||
* ============================================================ */ | * ============================================================ */ | ||
( function ( | ( function () { | ||
'use strict'; | 'use strict'; | ||
// ─── Cookie helpers ───────────────────────────────────── | |||
function getCookie( name ) { | function getCookie( name ) { | ||
var | var m = document.cookie.match( new RegExp( '(?:^|;\\s*)' + name + '=([^;]*)' ) ); | ||
return | return m ? decodeURIComponent( m[ 1 ] ) : null; | ||
} | } | ||
function deleteCookie( name ) { | |||
function | var hostname = window.location.hostname; | ||
var | var parts = hostname.split( '.' ); | ||
var | var domains = [ hostname, '' ]; | ||
if ( | if ( parts.length > 2 ) { | ||
domains.push( '.' + parts.slice( -2 ).join( '.' ) ); | |||
} | } | ||
domains.forEach( function ( d ) { | |||
var suffix = d ? '; domain=' + d : ''; | |||
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/' + suffix; | |||
} ); | |||
} | } | ||
// ─── 1. Mobile cookie nuke ────────────────────────────── | |||
var ua = navigator.userAgent || ''; | |||
var isMobile = /iPhone|iPad|iPod|Android.*Mobile|Mobile.*Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test( ua ); | |||
var mobileCookiesDeleted = false; | |||
if ( isMobile ) { | |||
[ 'stopMobileRedirect', 'mf_useformat' ].forEach( function ( name ) { | |||
if ( getCookie( name ) !== null ) { | |||
deleteCookie( name ); | |||
mobileCookiesDeleted = true; | |||
} | } | ||
} ); | } ); | ||
} | } | ||
/ | // ─── 2. Auto-lang residuo (cleanup definitivo) ────────── | ||
// Le versioni precedenti del Common.js settavano autolang_set per redirect | |||
// bidirezionali tra IT/RU. Lo cancelliamo SEMPRE: niente più auto-redirect. | |||
if ( getCookie( 'autolang_set' ) !== null ) { | |||
deleteCookie( 'autolang_set' ); | |||
} | } | ||
if ( getCookie( 'no_auto_lang_redirect' ) !== null ) { | |||
deleteCookie( 'no_auto_lang_redirect' ); | |||
} | } | ||
if ( | // ─── 3. Se mobile + appena pulito cookie + su Vector ─── | ||
// → reload per ottenere Minerva | |||
if ( mobileCookiesDeleted && | |||
document.body && | |||
/skin-vector/.test( document.body.className ) ) { | |||
window.location.reload(); | |||
} | } | ||
}( | }() ); | ||
/* ============================================================ */ | /* ============================================================ | ||
* NIENTE auto-redirect IT↔RU. | |||
* L'utente sceglie la lingua via icona globo (ULS) o URL. | |||
* ============================================================ */ | |||
Versione delle 10:06, 1 giu 2026
/* ============================================================
* Common.js v5 — Wiki Methode Paret
* ============================================================
*
* PRINCIPIO: Non interferire con le scelte dell'utente.
* URL decide il contenuto. L'icona globo (ULS) decide la UI.
* Niente redirect automatici incrociati.
*
* Le uniche logiche attive:
* 1. Pulizia cookie velenosi mobile (stopMobileRedirect, mf_useformat)
* → permette a MobileFrontend di servire sempre Minerva su UA mobile
* 2. Pulizia cookie autolang_set residuo da versioni precedenti
* → toglie l'auto-redirect bidirezionale che disturbava
* ============================================================ */
( function () {
'use strict';
// ─── Cookie helpers ─────────────────────────────────────
function getCookie( name ) {
var m = document.cookie.match( new RegExp( '(?:^|;\\s*)' + name + '=([^;]*)' ) );
return m ? decodeURIComponent( m[ 1 ] ) : null;
}
function deleteCookie( name ) {
var hostname = window.location.hostname;
var parts = hostname.split( '.' );
var domains = [ hostname, '' ];
if ( parts.length > 2 ) {
domains.push( '.' + parts.slice( -2 ).join( '.' ) );
}
domains.forEach( function ( d ) {
var suffix = d ? '; domain=' + d : '';
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/' + suffix;
} );
}
// ─── 1. Mobile cookie nuke ──────────────────────────────
var ua = navigator.userAgent || '';
var isMobile = /iPhone|iPad|iPod|Android.*Mobile|Mobile.*Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test( ua );
var mobileCookiesDeleted = false;
if ( isMobile ) {
[ 'stopMobileRedirect', 'mf_useformat' ].forEach( function ( name ) {
if ( getCookie( name ) !== null ) {
deleteCookie( name );
mobileCookiesDeleted = true;
}
} );
}
// ─── 2. Auto-lang residuo (cleanup definitivo) ──────────
// Le versioni precedenti del Common.js settavano autolang_set per redirect
// bidirezionali tra IT/RU. Lo cancelliamo SEMPRE: niente più auto-redirect.
if ( getCookie( 'autolang_set' ) !== null ) {
deleteCookie( 'autolang_set' );
}
if ( getCookie( 'no_auto_lang_redirect' ) !== null ) {
deleteCookie( 'no_auto_lang_redirect' );
}
// ─── 3. Se mobile + appena pulito cookie + su Vector ───
// → reload per ottenere Minerva
if ( mobileCookiesDeleted &&
document.body &&
/skin-vector/.test( document.body.className ) ) {
window.location.reload();
}
}() );
/* ============================================================
* NIENTE auto-redirect IT↔RU.
* L'utente sceglie la lingua via icona globo (ULS) o URL.
* ============================================================ */