MediaWiki:Common.js: Difference between revisions

added a temporary debug banner to see what's happening on your phone
Tag: Reverted
gave the mobile menu some actual links
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(document).ready(function() {
    $('#ca-nstab-main a').text('Article');
    $('#ca-history a').text('History');
    $('#ca-view a').text('Read');
});
// ==========================================================================
// ==========================================================================
// Force the branded desktop (Vector) skin for everyone, including phones.
// Minerva (mobile skin) main menu only ships Home/Random by default; it does
// The site auto-switches to MediaWiki's generic Minerva mobile skin based
// not pull in MediaWiki:Sidebar the way Vector's portlets do. This injects
// on user-agent, which has none of the custom theme/nav and is a much
// the same section links (kept in sync with MediaWiki:Sidebar by hand) into
// worse experience than the (now mobile-responsive) desktop skin.
// the native menu markup so mobile visitors actually get real navigation
//
// instead of just Home/Random/Settings/About/Disclaimers.
// The server does set a loop-guard cookie on the toggle ("stopMobileRedirect"),
// but it's HttpOnly (confirmed by testing), so client-side JS can never
// 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
// 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 () {
  // TEMPORARY DEBUG BUILD: the automatic redirect isn't firing on some real
   function initMinervaNav() {
  // 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 {
     try {
       var el = document.createElement('div');
      if (!document.body || !document.body.classList.contains('skin-minerva')) return;
       el.id = 'wov-debug-banner';
       var nav = document.getElementById('p-navigation');
       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;';
       if (!nav || document.getElementById('wov-minerva-extra-nav')) return;
      el.textContent = lines.join('\n');
 
      (document.body || document.documentElement).appendChild(el);
       var sections = [
        { heading: 'Guides', items: [
          ['Getting started', '/w/Getting_Started'],
          ['Interactive Map (Fullscreen)', 'https://jxlife.github.io/WindsOfValenMap/'],
          ['All skills', '/w/Skills'],
          ['All quests', '/w/Quests'],
          ['Combat guide', '/w/Combat']
        ]},
        { heading: 'Database', items: [
          ['Item database', '/w/Items'],
          ['NPC database', '/w/NPCs'],
          ['Set bonuses', '/w/Set_bonuses']
        ]},
        { heading: 'Skills', items: [
          ['Skill Calculator', '/w/Calculators'],
          ['Mining', '/w/Mining'],
          ['Smithing', '/w/Smithing'],
          ['Fishing', '/w/Fishing'],
          ['Potion Making', '/w/Potion_Making']
        ]},
        { heading: 'Tools', items: [
          ['About this wiki', '/w/Project:About'],
          ['Random page', '/w/Special:Random'],
          ['New files', '/w/Special:NewFiles'],
          ['Wanted pages', '/w/Special:WantedPages'],
          ['Wiki statistics', '/w/Special:Statistics']
        ]},
        { heading: 'Updates', items: [
          ['Recent changes', '/w/Special:RecentChanges']
        ]}
      ];
 
      var container = document.createElement('div');
      container.id = 'wov-minerva-extra-nav';
 
      sections.forEach(function (section) {
        var heading = document.createElement('div');
        heading.className = 'wov-minerva-nav-heading';
        heading.textContent = section.heading;
        container.appendChild(heading);
 
        var ul = document.createElement('ul');
        ul.className = 'toggle-list__list';
        section.items.forEach(function (item) {
          var li = document.createElement('li');
          li.className = 'toggle-list-item';
          var a = document.createElement('a');
          a.className = 'toggle-list-item__anchor';
          a.href = item[1];
          var label = document.createElement('span');
          label.className = 'toggle-list-item__label';
          label.textContent = item[0];
          a.appendChild(label);
          li.appendChild(a);
          ul.appendChild(li);
        });
        container.appendChild(ul);
      });
 
      nav.parentNode.insertBefore(container, nav.nextSibling);
     } catch (e) {}
     } catch (e) {}
  }
  function tryForceDesktop() {
    var log = [];
    try {
      log.push('readyState: ' + document.readyState);
      log.push('bodyClass: ' + (document.body ? document.body.className : 'NO BODY'));
      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 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) {
      log.push('FATAL ERROR: ' + e.message);
      showDebugBanner(log);
    }
   }
   }
   if (document.body) {
   if (document.body) {
     tryForceDesktop();
     initMinervaNav();
   } else {
   } else {
     document.addEventListener('DOMContentLoaded', tryForceDesktop);
     document.addEventListener('DOMContentLoaded', initMinervaNav);
   }
   }
})();
})();
$(document).ready(function() {
    $('#ca-nstab-main a').text('Article');
    $('#ca-history a').text('History');
    $('#ca-view a').text('Read');
});
// ==========================================================================
// ==========================================================================
// Valen Ledger — Gathering & Combat XP Calculator
// Valen Ledger — Gathering & Combat XP Calculator