Dead Frontier Inventory Counter

Detects true usable inventory slots (base + backpack)

  1. // ==UserScript==
  2. // @name Dead Frontier Inventory Counter
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.8
  5. // @description Detects true usable inventory slots (base + backpack)
  6. // @match https://fairview.deadfrontier.com/onlinezombiemmo/index.php*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10.  
  11.  
  12. window.BrowserImplant_InventoryCounter = true;
  13.  
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. const INVENTORY_URL = 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=25';
  19.  
  20. function createHiddenIframe(callback) {
  21. const iframe = document.createElement('iframe');
  22. iframe.style.display = 'none';
  23. iframe.src = INVENTORY_URL;
  24.  
  25. iframe.onload = () => {
  26. try {
  27. const doc = iframe.contentDocument || iframe.contentWindow.document;
  28.  
  29. let used = 0;
  30. let total = 0;
  31.  
  32. const allSlots = Array.from(doc.querySelectorAll('td.validSlot[data-slot]'));
  33.  
  34. allSlots.forEach(slot => {
  35. const inBackpack = slot.closest('#backpackdisplay');
  36. const isImplantOrJunk = slot.closest('#implants') || slot.closest('.equipped') || slot.closest('.weapon');
  37.  
  38. if (!isImplantOrJunk) {
  39. total++;
  40. if (slot.querySelector('.item')) used++;
  41. }
  42. });
  43.  
  44. callback({ used, total });
  45.  
  46. } catch (err) {
  47. console.error('[DF Inventory Iframe] Access error:', err);
  48. callback(null);
  49. }
  50. };
  51.  
  52. document.body.appendChild(iframe);
  53. }
  54.  
  55. function injectSidebarBox(inventory) {
  56. const targetTD = Array.from(document.querySelectorAll('td.design2010'))
  57. .find(td => td.getAttribute('background')?.includes('menu_div6.jpg'));
  58. if (!targetTD) return;
  59.  
  60. const box = document.createElement('div');
  61. box.style.margin = '4px auto';
  62. box.style.textAlign = 'center';
  63. box.style.fontSize = '11px';
  64. box.style.fontWeight = '600';
  65. box.style.textShadow = '1px 1px #000';
  66. box.style.lineHeight = '1.2';
  67.  
  68. if (!inventory) {
  69. box.textContent = 'Inventory: error';
  70. box.style.color = '#ccc';
  71. } else {
  72. const { used, total } = inventory;
  73. const free = total - used;
  74. const percent = total > 0 ? Math.round((used / total) * 100) : 0;
  75.  
  76. const color =
  77. percent >= 90 ? '#ff3333' :
  78. percent >= 50 ? '#ffff33' :
  79. '#00ff00';
  80.  
  81. box.textContent = `Inventory: ${used}/${total} (${free} free)`;
  82. box.style.color = color;
  83. }
  84.  
  85. targetTD.appendChild(box);
  86. }
  87.  
  88. window.addEventListener('load', () => {
  89. createHiddenIframe(injectSidebarBox);
  90. });
  91. })();