[GC] - SDB Removal Improvements

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

Από την 30/12/2023. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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