This Ain't A Phone

Automatically redirect from mobile webpages to the non-mobile equivalent

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         This Ain't A Phone
// @namespace    https://schiff.io
// @version      10
// @description  Automatically redirect from mobile webpages to the non-mobile equivalent
// @author       Hayden Schiff (oxguy3)
// @match        *://m.dailykos.com/*
// @match        *://m.facebook.com/*
// @match        *://m.imdb.com/*
// @match        *://mobile.nytimes.com/*
// @match        *://m.phys.org/*
// @match        *://m.sweclockers.com/*
// @match        *://mobile.twitter.com/*
// @match        *://m.mediawiki.org/*
// @match        *://*.m.wikibooks.org/*
// @match        *://m.wikidata.org/*
// @match        *://*.m.wikimedia.org/*
// @match        *://*.m.wikinews.org/*
// @match        *://*.m.wikipedia.org/*
// @match        *://*.m.wikiquote.org/*
// @match        *://m.wikisource.org/*
// @match        *://*.m.wikisource.org/*
// @match        *://*.m.wikiversity.org/*
// @match        *://*.m.wikivoyage.org/*
// @match        *://*.m.wiktionary.org/*
// @match        *://m.xkcd.com/*
// @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.dailykos.com', 'www.dailykos.com' ],
            [ 'm.facebook.com', 'www.facebook.com' ],
            [ 'm.imdb.com', 'imdb.com' ],
            [ 'm.mediawiki.org', 'www.mediawiki.org' ],
            [ 'mobile.nytimes.com', 'www.nytimes.com' ],
            [ 'm.phys.org', 'phys.org' ],
            [ 'm.sweclockers.com', 'sweclockers.com' ],
            [ 'mobile.twitter.com', 'twitter.com' ],
            [ 'm.wikidata.org', 'www.wikidata.org' ],
            [ 'm.wikisource.org', 'www.wikisource.org' ],
            [ 'm.xkcd.com', 'xkcd.com' ]
        ];

        // 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',
            'wikibooks.org',
            'wikimedia.org',
            'wikinews.org',
            'wikiquote.org',
            'wikisource.org',
            'wikiversity.org',
            'wikivoyage.org',
            'wiktionary.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;
    }
})();