[GC] - SDB Removal Improvements

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

30.12.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);
});