This Ain't A Phone

Automatically redirect from mobile webpages to the non-mobile equivalent

当前为 2018-09-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         This Ain't A Phone
// @namespace    https://schiff.io
// @version      7
// @description  Automatically redirect from mobile webpages to the non-mobile equivalent
// @author       Hayden Schiff (oxguy3)
// @match        *://m.facebook.com/*
// @match        *://m.imdb.com/*
// @match        *://mobile.nytimes.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.facebook.com', 'www.facebook.com' ],
            [ 'm.imdb.com', 'imdb.com' ],
            [ 'm.mediawiki.org', 'www.mediawiki.org' ],
            [ 'mobile.nytimes.com', 'www.nytimes.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;
    }
})();