MediaWiki:Common.js: Difference between revisions
fixed the redirect not firing on its own on real phones Tag: Reverted |
added a temporary debug banner to see what's happening on your phone Tag: Reverted |
||
| Line 20: | Line 20: | ||
// giving up on the first check. | // giving up on the first check. | ||
(function () { | (function () { | ||
// TEMPORARY DEBUG BUILD: the automatic redirect isn't firing on some real | |||
// phones and it can't be reproduced in any test environment available | |||
// here (Electron only fakes the user-agent string, it never actually runs | |||
// WebKit). Instead of guessing again, this shows what the script actually | |||
// sees directly on the page, and does NOT navigate away, so the banner | |||
// stays put to be read/screenshotted. Remove this block and restore the | |||
// plain redirect once the real cause is identified from that report. | |||
function showDebugBanner(lines) { | |||
try { | |||
var el = document.createElement('div'); | |||
el.id = 'wov-debug-banner'; | |||
el.style.cssText = 'position:fixed;top:0;left:0;right:0;z-index:99999;background:#111;color:#0f0;font:12px monospace;padding:8px;white-space:pre-wrap;word-break:break-all;max-height:60vh;overflow:auto;'; | |||
el.textContent = lines.join('\n'); | |||
(document.body || document.documentElement).appendChild(el); | |||
} catch (e) {} | |||
} | |||
function tryForceDesktop() { | function tryForceDesktop() { | ||
var log = []; | |||
try { | try { | ||
log.push('readyState: ' + document.readyState); | |||
var alreadyTried = false; | log.push('bodyClass: ' + (document.body ? document.body.className : 'NO BODY')); | ||
try { alreadyTried = !!sessionStorage.getItem('wovForcedDesktop'); } catch (e) {} | var isMinerva = !!(document.body && document.body.classList.contains('skin-minerva')); | ||
log.push('isMinerva: ' + isMinerva); | |||
if (!isMinerva) { log.push('DECISION: not Minerva, nothing to do'); showDebugBanner(log); return; } | |||
var | var storageWorks = true, alreadyTried = false; | ||
try { alreadyTried = !!sessionStorage.getItem('wovForcedDesktop'); } catch (e) { storageWorks = false; log.push('sessionStorage error: ' + e.message); } | |||
log.push('storageWorks: ' + storageWorks + ', alreadyTried: ' + alreadyTried); | |||
if (alreadyTried) { log.push('DECISION: already tried this session, stopping (would normally stay on Minerva)'); showDebugBanner(log); return; } | |||
var targetUrl = window.location.pathname + window.location.search + (window.location.search ? '&' : '?') + 'mobileaction=toggle_view_desktop'; | |||
log.push('DECISION: would redirect to: ' + targetUrl); | |||
log.push('cookie: ' + document.cookie); | |||
showDebugBanner(log); | |||
// Redirect intentionally disabled during this debug pass. | |||
} catch (e) { | } catch (e) { | ||
log.push('FATAL ERROR: ' + e.message); | |||
showDebugBanner(log); | |||
} | } | ||
} | } | ||