[GC] - SDB Removal Improvements

Never try to remove too many items from your SDB again!

2023-12-30 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        [GC] - SDB Removal Improvements
// @namespace   https://www.grundos.cafe
// @match       https://www.grundos.cafe/safetydeposit/*
// @license    MIT
// @version     1.0
// @author      Cupkait (& shoutout to Josh)
// @description Never try to remove too many items from your SDB again!
// ==/UserScript==

const createInventoryDiv = () => {
    const inventoryDiv = document.createElement('div');
    Object.assign(inventoryDiv.style, {
        position: 'fixed',
        bottom: '10px',
        left: '10px',
        padding: '10px',
        border: '1px solid #ccc',
    });
    document.body.appendChild(inventoryDiv);
    return inventoryDiv;
};

const updateInventoryInfo = async () => {
    try {
        const response = await fetch("/inventory/");
        if (!response.ok) throw new Error(`Network response was not ok: ${response.statusText}`);
        const html = await response.text();
        const inventoryHTML = $(html).find('main').find('p').eq(1).text();
        const currentItemCount = inventoryHTML.match(/You currently hold (.*?) items/)[1];
        const maxItemCount = inventoryHTML.match(/The maximum you should hold is (.*?)\./)[1];
        const availableSpaces = maxItemCount - currentItemCount;
        const remainSpaces = availableSpaces - countRemove;

        if (remainSpaces <= 0) {
            if (remainSpaces === 0) {
                inventoryDiv.innerHTML = 'You cannot select anymore!';
                inventoryDiv.style.background = 'orange';
            } else {
                inventoryDiv.innerHTML = 'You have too many selected!';
                inventoryDiv.style.background = 'red';
            }
        } else {
            inventoryDiv.innerHTML = `You can still remove <strong>${remainSpaces}</strong> more items.`;
            inventoryDiv.style.background = '#fff';
        }
    } catch (error) {
        console.error(error);
    }
};

let countRemove = 0;

const updateCountRemove = () => {
    countRemove = Array.from(document.querySelectorAll('input.form-control.rm'))
        .map(input => {
            const listedQuantity = parseInt(input.getAttribute('data-qty')) || 0;
            const enteredValue = parseInt(input.value) || 0;
            return Math.min(enteredValue, listedQuantity);
        })
        .reduce((sum, value) => sum + value, 0);

    console.log('countRemove:', countRemove);
    updateInventoryInfo();
};

const inventoryDiv = createInventoryDiv();
updateInventoryInfo();

document.querySelectorAll('input.form-control.rm').forEach(input => {
    input.addEventListener('input', updateCountRemove);
});