Jump to content

User:Steppres/vector-2022.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Steppres (talk | contribs) at 06:13, 30 March 2025 (always redirect to mobile version). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
  Force Wikipedia to use the mobile version on all devices.
  Redirects any desktop URL (en.wikipedia.org) to mobile (en.m.wikipedia.org)
  
  CC0
*/
(function() {
  const desktopPattern = /^https?:\/\/([a-z]+)\.wikipedia\.org(\/.*)?$/i;
  const match = window.location.href.match(desktopPattern);

  if (match && !window.location.hostname.startsWith('m.')) {
    const lang = match[1];
    const path = match[2] || '/';
    const mobileUrl = `https://${lang}.m.wikipedia.org${path}`;
    window.location.replace(mobileUrl);
  }
})();