MediaWiki:Common.js: Difference between revisions
cleaned up some dead code from the mobile fix Tag: Reverted |
fixed the redirect not firing on its own on real phones Tag: Reverted |
||
| Line 3: | Line 3: | ||
// The site auto-switches to MediaWiki's generic Minerva mobile skin based | // The site auto-switches to MediaWiki's generic Minerva mobile skin based | ||
// on user-agent, which has none of the custom theme/nav and is a much | // on user-agent, which has none of the custom theme/nav and is a much | ||
// worse experience than the (now mobile-responsive) desktop skin | // worse experience than the (now mobile-responsive) desktop skin. | ||
// | // | ||
// The server does set a loop-guard cookie on the toggle ("stopMobileRedirect"), | // The server does set a loop-guard cookie on the toggle ("stopMobileRedirect"), | ||
| Line 11: | Line 9: | ||
// actually read it - that check would always be dead code. sessionStorage | // actually read it - that check would always be dead code. sessionStorage | ||
// is the only guard we can use here, wrapped in its own try/catch so a | // is the only guard we can use here, wrapped in its own try/catch so a | ||
// browser that blocks storage access ( | // browser that blocks storage access doesn't cancel the whole redirect. | ||
// | // | ||
// This used to bail out permanently if document.body wasn't available yet | |||
// ("if (!document.body) return"), with no retry. Real-device testing (real | |||
// Safari/Chrome on iOS - NOT reproducible by spoofing the user-agent string | |||
// in a desktop Electron/Chromium test, since that never runs WebKit at all) | |||
// showed the redirect worked fine when triggered manually via URL, but never | |||
// fired on its own: this script runs before <body> exists in some real | |||
// mobile browsers, so it needs to wait for DOMContentLoaded instead of | |||
// giving up on the first check. | |||
(function () { | (function () { | ||
try { | function tryForceDesktop() { | ||
try { | |||
if (!document.body || !document.body.classList.contains('skin-minerva')) return; | |||
var alreadyTried = false; | |||
try { alreadyTried = !!sessionStorage.getItem('wovForcedDesktop'); } catch (e) {} | |||
if (alreadyTried) return; | |||
try { sessionStorage.setItem('wovForcedDesktop', '1'); } catch (e) {} | |||
var sep = window.location.search ? '&' : '?'; | |||
window.location.href = window.location.pathname + window.location.search + sep + 'mobileaction=toggle_view_desktop'; | |||
} catch (e) { | |||
// if even the basic checks are blocked, just leave the user on Minerva | |||
// rather than risk breaking the rest of the site's scripts. | |||
} | |||
} | |||
if (document.body) { | |||
tryForceDesktop(); | |||
} else { | |||
document.addEventListener('DOMContentLoaded', tryForceDesktop); | |||
} | } | ||
})(); | })(); | ||