从m.thepaper.cn转到www.thepaper.cn

Redirect m.thepaper.cn URLs to www.thepaper.cn with correct format

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         从m.thepaper.cn转到www.thepaper.cn
// @version      0.1
// @description  Redirect m.thepaper.cn URLs to www.thepaper.cn with correct format
// @author       bingqiang
// @match        https://m.thepaper.cn/*
// @grant        none
// @namespace https://greasyfork.org/users/1346278
// ==/UserScript==

(function() {
    'use strict';

    // Redirect function
    function redirectUrl() {
        var currentUrl = window.location.href;

        // Check if the URL starts with m.thepaper.cn and contains numbers
        if (currentUrl.startsWith('https://m.thepaper.cn/')) {
            // Extract ID (digits) from the URL
            var regex = /(\d+)/;
            var match = currentUrl.match(regex);
            if (match && match[1]) {
                var id = match[1];
                var newUrl = 'https://www.thepaper.cn/newsDetail_forward_' + id;
                // Redirect to the new URL
                window.location.replace(newUrl);
            }
        }
    }

    // Check if the URL starts with m.thepaper.cn
    if (window.location.hostname === 'm.thepaper.cn') {
        redirectUrl();
    }
})();