Greasy Fork 支持简体中文。

Museum Set Buttons

Adds quick access buttons for each flower and plushie.

// ==UserScript==
// @name         Museum Set Buttons
// @namespace    Titanic_
// @version      v2
// @description  Adds quick access buttons for each flower and plushie.
// @license      MIT
// @author       Titanic_ [2968477]
// @match        https://www.torn.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// ==/UserScript==

const plushies = {
    "Kitten": 215, "Sheep": 186, "Teddy Bear": 187, "Stingray": 618,
    "Wolverine": 261, "Chamois": 273, "Jaguar": 258, "Nessie": 266,
    "Red Fox": 268, "Monkey": 269, "Panda": 274, "Lion": 281, "Camel": 384,
    "type": "plushie"
};

const flowers = {
    "Edelweiss": 272, "Dahlia": 260, "Crocus": 263, "Banana Orchid": 617,
    "Orchid": 264, "Ceibo Flower": 271, "Heather": 267, "Cherry Blossom": 277,
    "Tribulus Omanense": 385, "African Violet": 282, "Peony": 276,
    "type": "flower"
};

let enabled = getData('msh-enabled') === 'false' ? false : true;

if (typeof GM_registerMenuCommand === 'function') {
    let overlayCommand;

    function updateOverlayButton() {
        const label = !enabled ? 'Show Overlay' : 'Hide Overlay';
        if (overlayCommand) GM_unregisterMenuCommand(overlayCommand);
        overlayCommand = GM_registerMenuCommand(label, function() {
            enabled = !enabled;
            setData('msh-enabled', enabled ? 'true' : 'false');
            updateOverlay();
            initCommands();
        });
    }

    function initCommands() {
        updateOverlayButton();
    }

    initCommands();
} else {
    console.error('[Set Helper] Monkey not detected!');
}



// MENU START //
function createDiv() {
    const div = document.createElement('div');
    div.id = 'set-container';
    if(!enabled) div.classList.add("set-hidden")

    const toggleVisibility = (listId) => {
        const list = document.getElementById(listId);
        list.style.display = list.style.display === 'none' ? 'flex' : 'none';
        setData(listId, list.style.display === 'flex');
        updateContainerHeight()
    };

    const childPlushies = createList(plushies, 'plushie');
    const childFlowers = createList(flowers, 'flower');

    div.appendChild(createButton('Toggle Flowers', () => toggleVisibility('flower-list'), "flower-toggle"));
    div.appendChild(childFlowers);

    div.appendChild(createButton('Toggle Plushies', () => toggleVisibility('plushie-list'), "plushie-toggle"));
    div.appendChild(childPlushies);

    document.body.appendChild(div);

    if (getData('flower-list') === 'false') {
        childFlowers.style.display = 'none';
    }
    if (getData('plushie-list') === 'false') {
        childPlushies.style.display = 'none';
    }

    updateContainerHeight();
}

function createList(items, type) {
    const div = document.createElement('div');
    div.id = `${type}-list`;

    Object.keys(items).forEach(item => {
        if (item === "type") return;
        const childDiv = document.createElement('div');
        childDiv.classList.add("set-item-container");
        childDiv.id = `set-id-${items[item]}`;

        const img = document.createElement('img');
        img.src = `https://torn.com/images/items/${items[item]}/small.png`;
        img.style.pointerEvents = 'auto';

        const a = document.createElement('a');
        a.textContent = item;
        a.href = `https://www.torn.com/page.php?sid=ItemMarket#/market/view=search&itemID=${items[item]}&itemName=${item.replace(" ", "+")}&itemtype=${items["type"]}`;
        a.classList.add("set-item");
        a.appendChild(img);

        childDiv.appendChild(a);
        div.appendChild(childDiv);
    });

    return div;
}

function createButton(text, onClick, id) {
    const button = document.createElement('button');
    button.textContent = text;
    button.classList.add("set-button");
    if (id) button.id = id;
    button.addEventListener("click", onClick);
    return button;
}

function updateContainerHeight() {
    const plushieList = $("#plushie-list").length && $("#plushie-list").css("display") !== 'none';
    const flowerList = $("#flower-list").length && $("#flower-list").css("display") !== 'none';

    if (!plushieList && !flowerList) {
        $("#set-container").css("height", "fit-content");
    } else {
        $("#set-container").css("height", "100%");
    }
}
// MENU END //

function getData(key) {
    return localStorage.getItem(key);
}

function setData(key, value) {
    localStorage.setItem(key, value);
}

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

createDiv();
addGlobalStyle(`
    #set-container { position: fixed; top: 0; right: 0; height: 100%; width: 175px; background-color: rgba(0, 0, 0, 0.5); z-index: 999999; pointer-events: none; display: flex; flex-direction: column; align-items: center; overflow-y: auto; }
    #plushie-list, #flower-list { width: 100%; pointer-events: auto; display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 5px; flex-direction: column; }
    .set-item-container { display: flex; width: 100%; }
    .set-item { color: white; text-decoration: none; border: 1px solid white; padding: 5px; width: 100%; pointer-events: auto; }
    .set-item:hover { opacity: .7 }
    .set-hidden { display: none !important }
    .set-button { pointer-events: auto; cursor: pointer; margin: 5px; padding: 5px; color: white; border-bottom: 1px solid white; }
    .set-button:hover { border: 2px solid white }
`);