蝦皮短網址

縮短蝦皮網址

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        蝦皮短網址
// @namespace   https://greasyfork.org/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.3
// ==/UserScript==

(function() {
    'use strict';

    var ShortURL

    // 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.idmlsn');// Find the target flex container
        if (flexContainer) {// Check if the flex container exists
            flexContainer.appendChild(CopyButton);//注入按鈕

            var URL=decodeURIComponent(location.href)

            if (/product/.test(URL)) {
                ShortURL=URL.replace(/^https:\/\//, '')
            }else{
            ShortURL = 'shopee.tw' + URL
                .replace(/^https:\/\/shopee.tw/, '')
                .replace(/\/.*-i\./, '/product/')
                .replace(/\?\S*/, '')
                .replace(/\./g, '/')
                
            }
        }
    }

//第一次執行
    setTimeout(function() {
        MainFun()
    },3000);
//循環
    var mz = location.href;
    setInterval(function () {
        if (mz != location.href) {
            mz=location.href;
            MainFun();
        }
    },5000);

})();