Greasy Fork

Greasy Fork is available in English.

电脑端页面

匹配常见移动端常见子域(m., h5., mobile., wap., touch., 3g.)将移动网址转换为www网址,如果失败则恢复原始网址。

当前为 2025-04-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         电脑端页面
// @version      1.2
// @namespace    http://greasyfork.icu/users/1171320
// @description  匹配常见移动端常见子域(m., h5., mobile., wap., touch., 3g.)将移动网址转换为www网址,如果失败则恢复原始网址。
// @author       yzcjd
// @author2     Lama AI 辅助
// @match        *://m.*/*
// @match        *://h5.*/*
// @match        *://mobile.*/*
// @match        *://wap.*/*
// @match        *://touch.*/*
// @match        *://3g.*/*
// @run-at       document-start
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    const currentUrl = location.href;
    const hostname = location.hostname;

    // 防止跳转死循环:跳转后设置标记
    if (sessionStorage.getItem('__pc_redirected__')) return;

    // 正则匹配常见移动子域
    const mobilePrefixPattern = /^(m|h5|mobile|wap|touch|3g)\./i;
    if (!mobilePrefixPattern.test(hostname)) return;

    // 将匹配到的移动前缀替换为 www.
    const pcHostname = hostname.replace(mobilePrefixPattern, 'www.');
    const pcUrl = currentUrl.replace(hostname, pcHostname);

    // 检查目标PC页面是否存在
    fetch(pcUrl, { method: 'HEAD' })
        .then(response => {
            if (response.ok) {
                sessionStorage.setItem('__pc_redirected__', '1'); // 设置跳转标记
                window.location.href = pcUrl; // 跳转到PC版
            } else {
                console.warn('[跳转失败] PC版返回状态:', response.status);
            }
        })
        .catch(error => {
            console.warn('[跳转失败] 网络错误:', error);
        });
})();