[GC] - SDB Removal Improvements

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

  1. // ==UserScript==
  2. // @name [GC] - SDB Removal Improvements
  3. // @namespace https://www.grundos.cafe
  4. // @match https://www.grundos.cafe/safetydeposit/*
  5. // @license MIT
  6. // @version 1.0
  7. // @author Cupkait (& shoutout to Josh)
  8. // @description Never try to remove too many items from your SDB again!
  9. // ==/UserScript==
  10.  
  11. const createInventoryDiv = () => {
  12. const inventoryDiv = document.createElement('div');
  13. Object.assign(inventoryDiv.style, {
  14. position: 'fixed',
  15. bottom: '10px',
  16. left: '10px',
  17. padding: '10px',
  18. border: '1px solid #ccc',
  19. });
  20. document.body.appendChild(inventoryDiv);
  21. return inventoryDiv;
  22. };
  23.  
  24. const updateInventoryInfo = async () => {
  25. try {
  26. const response = await fetch("/inventory/");
  27. if (!response.ok) throw new Error(`Network response was not ok: ${response.statusText}`);
  28. const html = await response.text();
  29. const inventoryHTML = $(html).find('main').find('p').eq(1).text();
  30. const currentItemCount = inventoryHTML.match(/You currently hold (.*?) items/)[1];
  31. const maxItemCount = inventoryHTML.match(/The maximum you should hold is (.*?)\./)[1];
  32. const availableSpaces = maxItemCount - currentItemCount;
  33. const remainSpaces = availableSpaces - countRemove;
  34.  
  35. if (remainSpaces <= 0) {
  36. if (remainSpaces === 0) {
  37. inventoryDiv.innerHTML = 'You cannot select anymore!';
  38. inventoryDiv.style.background = 'orange';
  39. } else {
  40. inventoryDiv.innerHTML = 'You have too many selected!';
  41. inventoryDiv.style.background = 'red';
  42. }
  43. } else {
  44. inventoryDiv.innerHTML = `You can still remove <strong>${remainSpaces}</strong> more items.`;
  45. inventoryDiv.style.background = '#fff';
  46. }
  47. } catch (error) {
  48. console.error(error);
  49. }
  50. };
  51.  
  52. let countRemove = 0;
  53.  
  54. const updateCountRemove = () => {
  55. countRemove = Array.from(document.querySelectorAll('input.form-control.rm'))
  56. .map(input => {
  57. const listedQuantity = parseInt(input.getAttribute('data-qty')) || 0;
  58. const enteredValue = parseInt(input.value) || 0;
  59. return Math.min(enteredValue, listedQuantity);
  60. })
  61. .reduce((sum, value) => sum + value, 0);
  62.  
  63. console.log('countRemove:', countRemove);
  64. updateInventoryInfo();
  65. };
  66.  
  67. const inventoryDiv = createInventoryDiv();
  68. updateInventoryInfo();
  69.  
  70. document.querySelectorAll('input.form-control.rm').forEach(input => {
  71. input.addEventListener('input', updateCountRemove);
  72. });