蝦皮短網址DS

產生一個複製短網址的按鈕

目前为 2024-09-27 提交的版本。查看 最新版本

// ==UserScript==
// @name        蝦皮短網址DS
// @match       *shopee.tw/*
// @author      Dabinn/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
// @namespace https://gf.qytechs.cn/users/185744
// ==/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('https://'+ShortURL);
        CopyButton.textContent = 'Copied!';
        setTimeout(function() {
            CopyButton.textContent = 'Short URL';
        }, 1000);
    });

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

            var URL=decodeURIComponent(location.href)

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

//第一次執行
// 如果頁面開在背景tab,CopyButton建立後會被清掉(可能是蝦皮在focus時有作額外處理)
// 改成onfocus再建立CopyButton比較保險
    window.onfocus = function() {
        setTimeout(function() {
            MainFun()
        },1000);
    };
//循環
/*
    var mz = location.href;
    setInterval(function () {
        if (mz != location.href) {
            mz=location.href;
            MainFun();
        }
    },5000);
*/
})();

QingJ © 2025

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