4

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?

2

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.

1

Simply scroll down to the bottom of the page and click "Desktop".

footer at bottom of Wikipedia mobile

I think you'll find that most sites with mobile versions, especially those that auto-detect mobile browsers, have such a feature (including Stack Exchange).

  • It does not seem to save that preference though. Does it for you? – Lenar Hoyt Aug 14 '16 at 15:48
  • I'm surprised it doesn't set a cookie for future visits. – ale Aug 14 '16 at 16:00
1

I'm a developer on the Wikimedia mobile site.

If you use the desktop link at the bottom of the page and have cookies enabled this should bypass Varnish and in future visits you should land on the desktop site (see https://en.wikipedia.org/wiki/Wikipedia:Enable_mobile_version).

There are various Chrome/Firefox extensions that will also do this for you if you are looking for something which does not rely on cookies. e.g. https://chrome.google.com/webstore/detail/mobile2desktop-wikipedia/hgdfjjhaahfdggnecdecjekkimepkpaf?hl=en

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.