自用

111

目前為 2025-10-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         自用
// @namespace    Rayu
// @version      2.4
// @description  111
// @author       Rayu
// @license MIT
// @match        https://xiapi.xiapibuy.com/*
// @match        *://shopee.tw/*
// @match        *://shopee.ph/*
// @match        *://shopee.sg/*
// @match        *://shopee.com.my/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const url = window.location.href;

    // 1. 重定向 xiapi.xiapibuy.com 到 shopee.tw
    if (url.startsWith("https://xiapi.xiapibuy.com/")) {
        const path = window.location.pathname + window.location.search + window.location.hash;
        const newUrl = "https://shopee.tw" + path;
        window.location.replace(newUrl);
        return;  // 避免继续执行下面代码
    }

    // 2. 移除 Shopee 商品页面追踪器及清理 URL
    const reg = /\-i\.([\d]+)\.([\d]+)/;
    const cleanURL = (url) => {
        const match = url.match(reg);
        if (!match) return url;
        return `/product/${match[1]}/${match[2]}`;
    };

    // 如果当前URL包含追踪参数,自动跳转至干净URL
    if (reg.test(window.location.href)) {
        const clean = `${window.location.origin}${cleanURL(window.location.href)}`;
        if (clean !== window.location.href) {
            window.location.replace(clean);
            return; // 跳转避免继续执行后续代码
        }
    }

    // 监听历史记录变更(pushState, replaceState),替换 URL 中的追踪参数
    const originalPushState = history.pushState;
    const originalReplaceState = history.replaceState;

    history.pushState = function(state, title, url) {
        if (url) { url = cleanURL(url); }
        return originalPushState.call(this, state, title, url);
    };

    history.replaceState = function(state, title, url) {
        if (url) { url = cleanURL(url); }
        return originalReplaceState.call(this, state, title, url);
    };

    // 3. shopee.tw 页面样式修改,包括高度自适应修改
    if (url.startsWith("https://shopee.tw/")) {

        const selectors = [
            "#main > div:nth-child(2) > div.t5pFIU > div > div > div > div > div > div.shop-page > div > div.container",
            "#main > div.theme--ofs > div.t5pFIU > div > div > div > div > div > div.shop-page > div > div.container",
            "#sll2-normal-pdp-main > div > div > div > div.container",
            "#sll2-normal-pdp-main > div > div > div > div.container > section > section.flex.flex-auto.YTDXQ0 > div > div.y_zeJr > div > div.flex.KIoPj6.W5LiQM > div > section:nth-child(1) > div > div"
        ];

        let modified = false;

        // 核心应用样式函数
        const applyStyles = () => {
            const container0 = document.querySelector(selectors[0]);
            if (container0) {
                container0.style.width = "1700px";
                container0.style.marginLeft = "auto";
                container0.style.marginRight = "auto";
            }

            const container = document.querySelector(selectors[1]);
            if (container) {
                container.style.width = "1600px";
                container.style.marginLeft = "auto";
                container.style.marginRight = "auto";
            }

            const el1 = document.querySelector(selectors[2]);
            if (el1) {
                el1.style.width = "1600px";
            }

            const el2 = document.querySelector(selectors[3]);
            if (el2) {
                el2.style.maxHeight = "unset";
                el2.style.overflow = "visible";

                const j7 = el2.querySelector(".j7HL5Q");
                if (j7) {
                    j7.style.maxHeight = "unset";
                    j7.style.overflow = "visible";
                }
            }

            // 判断关键元素是否都已应用样式
            if (container0 && container && el1 && el2) {
                return true;
            }
            return false;
        };

        // 先尝试立即修改一次
        if (applyStyles()) {
            modified = true;
        }

        if (!modified) {
            // 使用 MutationObserver 监听 DOM 变化
            const observer = new MutationObserver(() => {
                if (applyStyles()) {
                    modified = true;
                    observer.disconnect(); // 成功后断开监听
                }
            });

            // 监听 body 子树变化
            observer.observe(document.body, {childList: true, subtree: true});

            // 10秒超时停止监听,防止无限执行
            setTimeout(() => {
                if (!modified) {
                    observer.disconnect();
                    console.warn("Shopee前台样式修正超时,停止监听");
                }
            }, 10000);
        }
    }

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址