Wikipedia – Permanently Disable Mobile Version of Wikipedia on Mobile Devices

wikipedia

I've seen that there are user scripts that Wikipedia users can add to their user profiles. Is there a way to add detect whether the mobile is active and redirect to the desktop version this way?

Best Answer

My solution uses the a of MediaWiki which allows you to load custom JavaScript into all visited pages while you're logged in. To use it, create an account, navigate to the Appearance section of your preferences and click on Custom JavaScript for Shared CSS/JavaScript for all skins. Paste the following script into the editor there:

(function () {
     // Find the link used to switch to the desktop view.
     var desktopLink = document.getElementById("mw-mf-display-toggle");

     if (desktopLink === null) {
          return;
     }

     var href = desktopLink.getAttribute('href')

     // Make sure we're not already in the desktop view, which could lead to
     // an infinite loop.
     if (href.indexOf('.m.') > -1) {
          return;
     }

     // Navigate to the new URL, replacing the history element, as if we were
     // never on the mobile site! You can use .assign() instead, if you want to
     // keep the URL of the mobile site in your history.
     window.location.replace(href);
})()

When the mobile version of a page is loaded, it will look for the Desktop link at the bottom of the page and navigate to the linked URL.

Make sure to switch to the desktop version when you log in to your account on your phone. Only then will it allow you to choose Keep me logged in (for up to 365 days).

This code relies on details of how the link to the desktop site can be identified. Please ping me in the comments when this breaks and I will happily provide an updated version here.