Skip to content

Instantly share code, notes, and snippets.

@auxiliary-character
Created May 6, 2020 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auxiliary-character/646c0caa546539c482d45b7a75ae9e50 to your computer and use it in GitHub Desktop.
Save auxiliary-character/646c0caa546539c482d45b7a75ae9e50 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Mobile Redirect
// @version 1.0
// @description general purpose mobile->desktop redirect
// @author auxchar
// @match *://*/*
// @grant none
// ==/UserScript==
function redirect_mobile(matcher){
var match = matcher.exec(window.location);
if(match != null) {
var uri = match[1] + match[2];
window.location.replace(uri);
}
}
var standard_matcher = /(https?:\/\/)(?:mobile|m)\.(.*)/;
redirect_mobile(standard_matcher);
//wikipedia has en.m.whatever for it's schema, which requires its own regex
var wikipedia_matcher = /(https?:\/\/en\.)m\.(.*)/
redirect_mobile(wikipedia_matcher);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment