MediaWiki:Common.js: Difference between revisions
force desktop skin on mobile instead of generic Minerva skin Tag: Reverted |
fixed the mobile redirect so it actually sticks now Tag: Reverted |
||
| Line 5: | Line 5: | ||
// worse experience than the (now mobile-responsive) desktop skin. This | // worse experience than the (now mobile-responsive) desktop skin. This | ||
// runs as early as possible to minimize the flash of the wrong skin before | // runs as early as possible to minimize the flash of the wrong skin before | ||
// redirecting. | // redirecting. | ||
// | // | ||
// The real loop-guard is the cookie this site's toggle actually sets | |||
// (confirmed by testing: "stopMobileRedirect=true", not the generic | |||
// MobileFrontend "mf_useformat" name assumed earlier) since it's set by | |||
// the server and survives across tabs/sessions. sessionStorage is only a | |||
// secondary backstop, wrapped in its own try/catch, so that browsers which | |||
// block storage access (common in some in-app/embedded browsers) don't | |||
// silently cancel the whole redirect and strand the user on Minerva. | |||
(function () { | (function () { | ||
try { | try { | ||
if (!document.body || !document.body.classList.contains('skin-minerva')) return; | if (!document.body || !document.body.classList.contains('skin-minerva')) return; | ||
if (document.cookie.indexOf(' | if (document.cookie.indexOf('stopMobileRedirect=true') !== -1) return; | ||
var alreadyTried = false; | |||
sessionStorage.setItem('wovForcedDesktop', '1'); | try { alreadyTried = !!sessionStorage.getItem('wovForcedDesktop'); } catch (e) {} | ||
if (alreadyTried) return; | |||
try { sessionStorage.setItem('wovForcedDesktop', '1'); } catch (e) {} | |||
var sep = window.location.search ? '&' : '?'; | var sep = window.location.search ? '&' : '?'; | ||
window.location.href = window.location.pathname + window.location.search + sep + 'mobileaction=toggle_view_desktop'; | window.location.href = window.location.pathname + window.location.search + sep + 'mobileaction=toggle_view_desktop'; | ||
} catch (e) { | } catch (e) { | ||
// if | // if even the basic checks are blocked, just leave the user on Minerva | ||
// than risk breaking the rest of the site's scripts. | // rather than risk breaking the rest of the site's scripts. | ||
} | } | ||
})(); | })(); | ||