GC - Copy SDB Inventory

Adds a button to your SDB page above your items. When clicked it copies all the items on the current page.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GC - Copy SDB Inventory
// @namespace    http://tampermonkey.net/
// @version      1.1
// @author       AshyAsh
// @description  Adds a button to your SDB page above your items. When clicked it copies all the items on the current page.
// @match        https://www.grundos.cafe/safetydeposit/*
// @grant        GM_setClipboard
// @license      MIT   
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// ==/UserScript==

(function() {
    'use strict';

    // Function to add custom CSS
    function addCustomCSS() {
        const css = `
            .custom-copy-button {
              background-color: #ACE1AF;
              border: 2px solid #6ECB73;
              padding: 5px 10px 15px 10px;
              margin: 10px;
              cursor: pointer;
              width: 85%;
              font-weight: 600;
              letter-spacing: 2px;
              text-transform: uppercase;
            }

            .custom-copy-button:hover {
                background-color: #AFADE1;
                letter-spacing: 3px;
                border: 2px solid #726FCA;
            }

            .custom-copy-button.copied {
                background-color: #03C03C;
                color: white;
                border: 2px solid #6ECB73;
            }
        `;

        const head = document.head || document.getElementsByTagName('head')[0];
        const style = document.createElement('style');
        style.type = 'text/css';
        style.appendChild(document.createTextNode(css));
        head.appendChild(style);
    }

    // Function to extract text and copy to clipboard
    function copyText() {
        let elements = document.querySelectorAll('.data.flex-column.small-gap.break strong');
        let textList = [];

        elements.forEach(element => {
            textList.push(element.textContent);
        });

        GM_setClipboard(textList.join("\n"));

        // Change button appearance upon successful copy
        copyButton.classList.add('copied');
        copyButton.textContent = 'Items Copied!';
    }

    // Add custom CSS to the page
    addCustomCSS();

    // Create and insert a button to trigger the copy function
    let copyButton = document.createElement('button');
    copyButton.textContent = 'Copy Inventory';
    copyButton.className = 'custom-copy-button';
    copyButton.addEventListener('click', function(event) {
        event.preventDefault(); // Prevent any default button behavior
        copyText();
    });

    // Select the target element to place the button above
    let targetElement = document.querySelector('.market_grid.sdb.margin-1');

    if (targetElement) {
        targetElement.parentNode.insertBefore(copyButton, targetElement);
    }
})();