IMVU Ez-PID copier

Copy PID to clipboard by left clicking

当前为 2024-08-19 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         IMVU Ez-PID copier
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Copy PID to clipboard by left clicking
// @author       Spikes, Spcckz @discord
// @match        *://*/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    const pidElement = document.querySelector('#product-cfl-pid'); // Cache the PID element

    if (!pidElement) return; // Exit if PID element is not found

    // Preload tooltip and popup elements
    const tooltip = document.createElement('div');
    tooltip.textContent = 'Click to Copy';
    tooltip.className = 'copy-tooltip';
    tooltip.style.position = 'absolute';
    tooltip.style.display = 'none'; // Initially hidden
    document.body.appendChild(tooltip);

    const popup = document.createElement('div');
    popup.textContent = 'Copied - Shop Spikes!';
    popup.className = 'copy-popup';
    popup.style.position = 'absolute';
    popup.style.display = 'none'; // Initially hidden
    document.body.appendChild(popup);

    // Function to handle copying to clipboard and showing popup
    function copyToClipboard(event) {
        const pidText = pidElement.textContent;

        // Remove tooltip when clicked
        tooltip.style.display = 'none';

        // Copy the PID number to the clipboard
        navigator.clipboard.writeText(pidText).then(() => {
            // Position popup relative to the PID element
            const rect = pidElement.getBoundingClientRect();
            popup.style.left = `${rect.left + window.scrollX + rect.width + 10}px`;
            popup.style.top = `${rect.top + window.scrollY}px`;
            popup.style.display = 'block';

            // Remove popup after 1.5 seconds
            setTimeout(() => {
                popup.style.display = 'none';
            }, 1500);
        });
    }

    // Function to show tooltip on hover
    function showTooltip(event) {
        // Position tooltip relative to the PID element
        const rect = pidElement.getBoundingClientRect();
        tooltip.style.left = `${rect.left + window.scrollX + rect.width + 10}px`;
        tooltip.style.top = `${rect.top + window.scrollY}px`;
        tooltip.style.display = 'block';
    }

    // Function to highlight PID element on hover
    function highlightOnHover() {
        pidElement.style.border = '2px solid #0073e6'; // Add blue border
        pidElement.style.backgroundColor = '#f0f8ff';  // Add light background color
    }

    // Function to remove highlight on mouseout
    function removeHighlight() {
        pidElement.style.border = ''; // Reset border
        pidElement.style.backgroundColor = ''; // Reset background color
        tooltip.style.display = 'none'; // Hide tooltip on mouseout
    }

    // Add styles for the popup, tooltip, and hover highlight
    GM_addStyle(`
        .copy-popup {
            background: #333;
            color: white;
            padding: 5px 10px;
            border-radius: 5px;
            font-size: 12px;
            pointer-events: none;
            z-index: 1000;
            transition: opacity 0.2s ease-in-out;
        }

        .copy-tooltip {
            background: #555;
            color: white;
            padding: 3px 8px;
            border-radius: 4px;
            font-size: 11px;
            pointer-events: none;
            z-index: 1000;
            transition: opacity 0.2s ease-in-out;
        }

        #product-cfl-pid {
            transition: background-color 0.2s ease-in-out, border 0.2s ease-in-out;
        }
    `);

    // Attach event listeners to the PID element
    pidElement.addEventListener('mouseover', function (event) {
        highlightOnHover();
        showTooltip(event);
    });

    pidElement.addEventListener('mouseout', function () {
        removeHighlight();
    });

    pidElement.addEventListener('click', function (event) {
        copyToClipboard(event);
    });
})();