User:Amousey/common.js

// ==UserScript== // @name        This Ain't A Phone // @namespace   https://schiff.io // @version      9 // @description Automatically redirect from mobile webpages to the non-mobile equivalent // @author      Hayden Schiff (oxguy3) // @match       *://m.mediawiki.org/* // @match       *://*.m.wikimedia.org/* // @match       *://*.m.wikipedia.org/* // @grant       none // @run-at      document-start // ==/UserScript==

(function {   'use strict';

// Checks if the location is a mobile site, and returns the URL of the non-mobile equivalent // Params: loc: window.location // Returns: string of new URL, or false if no match function checkLocation(loc) {

// simple hostname replacement rules var hostRules = [ [ 'm.mediawiki.org', 'www.mediawiki.org' ], [ 'en.m.wikipedia.org', 'en.wikipedia.org' ] ];

// shared logic for sites that only require a changed hostname for (var i = 0; i < hostRules.length; i++) { var rule = hostRules[i]; if (loc.host == rule[0]) { return loc.href.replace('//'+rule[0], '//'+rule[1]); }       }

// special logic for Wikimedia sites (too many subdomains to list individually) var wikimediaHosts = [ 'wikipedia.org', 'wikimedia.org' ];       for (var i = 0; i < wikimediaHosts.length; i++) { var wmHost = wikimediaHosts[i]; if (loc.host.endsWith('.m.'+wmHost)) { var newHost = loc.host.slice(0, 0 - ('m.'+wmHost).length) + wmHost; return loc.protocol + "//" + newHost + ":" + loc.port + loc.pathname + loc.search + loc.hash; }       }

return false; }

var destination = checkLocation(window.location); if (destination !== false) { window.location.href = destination; } });

// de Wikipedia veAutocorrect.js // runs code from my User:Amousey/monobook.js // needs editing for script name // and domain names because it won't run on all wikis //Benutzer:Schnark/js/veAutocorrect.js mw.loader.using('ext.visualEditor.desktopArticleTarget.init').done(function {	mw.libs.ve.addPlugin(function  { var d = $.Deferred; mw.hook('userjs.script-ready.monobook').add(d.resolve); mw.loader.load('https://www.mediawiki.org/w/index.php?title=User:Amousey/monobook.js&action=raw&ctype=text/javascript'); return d.promise; }); });