Greasy Fork

Greasy Fork is available in English.

蝦皮短網址

縮短蝦皮網址

当前为 2023-11-12 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        蝦皮短網址
// @namespace   http://greasyfork.icu/zh-TW/scripts/479591
// @match       *shopee.tw/*
// @author      czh/XPRAMT
// @icon        https://www.google.com/s2/favicons?sz=64&domain=shopee.tw
// @run-at      document-start
// @license     GNU GPLv3
// @description 縮短蝦皮網址
// @version 1.1
// ==/UserScript==

(function() {
    'use strict';

    var ShortURL=location.href;

    // Create a button
    var CopyButton = document.createElement('button');
    CopyButton.className = 'CopyButton'; // Add your custom class  tSCitv
    CopyButton.setAttribute('aria-label', 'Copy');
    CopyButton.textContent = 'Short URL';

    // 设置按钮样式
    CopyButton.style.backgroundColor = 'white';
    CopyButton.style.border = 'none';
    CopyButton.style.fontSize = '15px';
    CopyButton.style.lineHeight = '0px';
    CopyButton.style.cursor = 'pointer';

    // Add button click event
    CopyButton.addEventListener('click', function() {
        navigator.clipboard.writeText(ShortURL);
        CopyButton.textContent = 'Copied!';
        setTimeout(function() {
            CopyButton.textContent = 'Short URL';
        }, 1000);
    });

    function MainFun() {
        var flexContainer = document.querySelector('.flex.items-center.V5X-KA');// Find the target flex container
        if (flexContainer) {// Check if the flex container exists
            flexContainer.appendChild(CopyButton);//注入按鈕

            var utm = location.href.match(/\?.*\=.*/)
            if (utm == null){
                return
            }else{
                ShortURL = location.href.replace(/\?.*\=.*/, "");
            }

            var url = location.href.match(/\/.*-i.\d+.\d+\?/)
            if (url == null){
                return
            }else{
                ShortURL = location.href.replace(/.*-i.(\d+).(\d+)/, "product/$1/$2");
            }

            var url2 = ShortURL.match(/\?.*\=.*/)
            if (url2 == null){
                return
            }else{
                ShortURL = 'shopee.tw/' + ShortURL.replace(/\?.*\=.*/, "");
            }
        }
    }
//第一次執行
    setTimeout(function() {
        MainFun()
    },3000);
//循環
    var mz = location.href;
    setInterval(function () {
        if (mz != location.href) {
            mz=location.href;
            MainFun();
        }
    },3000);

})();