MediaWiki:Common.js

From Lenn's Fun Stuff

Revision as of 22:40, 16 March 2026 by LennLeaf (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* FORCE DESKTOP MODE ON MOBILE */
if ( window.location.href.indexOf('mobileaction=toggle_view_mobile') === -1 && 
     window.location.href.indexOf('mobileaction=toggle_view_desktop') === -1 &&
     /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    
    var url = new URL(window.location.href);
    url.searchParams.set('mobileaction', 'toggle_view_desktop');
    window.location.href = url.href;
}

/* FORCE DESKTOP SCALE */
(function() {
    var meta = document.createElement('meta');
    meta.name = "viewport";
    meta.content = "width=1200, initial-scale=0.3, maximum-scale=1.0";
    document.getElementsByTagName('head')[0].appendChild(meta);
})();

/* Adjust Viewport for Mobile but stay in Mobile Mode */
if (window.innerWidth < 1200) {
    $('meta[name="viewport"]').remove();
    $('head').append('<meta name="viewport" content="width=1200, initial-scale=0.3, user-scalable=yes">');
}

/* Zoom out on Mobile to fit the Desktop width */
if (window.innerWidth < 1200) {
    var viewportMeta = document.querySelector('meta[name="viewport"]');
    if (viewportMeta) {
        viewportMeta.setAttribute('content', 'width=1200, initial-scale=0.3');
    }
}

/* FORCE DESKTOP SCALE ON MOBILE */
(function() {
    var viewport = document.querySelector("meta[name=viewport]");
    var content = "width=1200, initial-scale=0.3, maximum-scale=1.0, user-scalable=yes";
    
    if (viewport) {
        viewport.setAttribute('content', content);
    } else {
        $('head').append('<meta name="viewport" content="' + content + '">');
    }
})();