mod testing

QoL features for Resurviv/Namerio

  1. // ==UserScript==
  2. // @name mod testing
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-08-31
  5. // @description QoL features for Resurviv/Namerio
  6. // @author Blubbled
  7. // @match http://resurviv.biz/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. function toggleUncappedFPS(enabled) {
  15. window.requestAnimationFrame = function(callback) {
  16. return setTimeout(callback, 1);
  17. };
  18. }
  19.  
  20. function periodicallyShowKillCounter() {
  21. showKillCounter();
  22. setTimeout(periodicallyShowKillCounter, 100);
  23. }
  24.  
  25. function showKillCounter() {
  26. var killCounter = document.getElementById('ui-kill-counter-wrapper');
  27. if (killCounter) {
  28. killCounter.style.display = 'block';
  29.  
  30. var counterText = killCounter.querySelector('.counter-text');
  31. if (counterText) {
  32. counterText.style.minWidth = '30px';
  33. }
  34. }
  35. }
  36.  
  37. function calculateAverageBoostWidth() {
  38. var counterLengths = [98.5, 98.5, 147.75, 49.25];
  39. var boostCounters = document.querySelectorAll('#ui-boost-counter .ui-bar-inner');
  40. var totalWidth = 0;
  41.  
  42. boostCounters.forEach(function(counter, index) {
  43. var widthPercentage = parseFloat(counter.style.width);
  44. var unitLength = counterLengths[index];
  45. totalWidth += (widthPercentage / 100) * unitLength;
  46. });
  47.  
  48. var totalUnitLength = counterLengths.reduce((a, b) => a + b, 0);
  49. var averageWidthPercentage = (totalWidth / totalUnitLength) * 100;
  50.  
  51. return averageWidthPercentage.toFixed(2) + "%";
  52. }
  53.  
  54. function toggleUIElementDisplay(enabled) {
  55. if (enabled) {
  56.  
  57. var healthBarWidthCopy = document.createElement('span');
  58. healthBarWidthCopy.id = 'health-bar-width-copy';
  59. healthBarWidthCopy.classList.add('unselectable');
  60. healthBarWidthCopy.style.position = 'fixed';
  61. healthBarWidthCopy.style.fontSize = '25px';
  62. healthBarWidthCopy.style.fontWeight = 'bold';
  63. healthBarWidthCopy.style.display = 'none';
  64.  
  65. var ammoCountCopy = document.createElement('span');
  66. ammoCountCopy.id = 'ammo-count-copy';
  67. ammoCountCopy.classList.add('unselectable');
  68. ammoCountCopy.style.position = 'fixed';
  69. ammoCountCopy.style.fontSize = '25px';
  70. ammoCountCopy.style.fontWeight = 'bold';
  71. ammoCountCopy.style.display = 'none';
  72.  
  73. var weaponNameCopy = document.createElement('span');
  74. weaponNameCopy.id = 'weapon-name-copy';
  75. weaponNameCopy.classList.add('unselectable');
  76. weaponNameCopy.style.position = 'fixed';
  77. weaponNameCopy.style.fontSize = '20px';
  78. weaponNameCopy.style.fontWeight = 'bold';
  79. weaponNameCopy.style.display = 'none';
  80.  
  81. var boostWidthCopy = document.createElement('span');
  82. boostWidthCopy.id = 'boost-width-copy';
  83. boostWidthCopy.classList.add('unselectable');
  84. boostWidthCopy.style.position = 'fixed';
  85. boostWidthCopy.style.fontSize = '20px';
  86. boostWidthCopy.style.fontWeight = 'bold';
  87. boostWidthCopy.style.color = 'orange';
  88. boostWidthCopy.style.display = 'none';
  89.  
  90. function updateHealthBarWidthCopy() {
  91. var healthBar = document.getElementById('ui-health-actual');
  92. if (healthBar && healthBar.offsetWidth > 0 && healthBar.offsetHeight > 0) {
  93. var healthBarWidth = Math.round(parseFloat(healthBar.style.width));
  94. var healthBarColor = healthBar.style.backgroundColor;
  95.  
  96. healthBarWidthCopy.textContent = healthBarWidth + "%";
  97. healthBarWidthCopy.style.color = healthBarColor;
  98. healthBarWidthCopy.style.display = 'block';
  99. } else {
  100. healthBarWidthCopy.style.display = 'none';
  101. }
  102. }
  103.  
  104. function updateAmmoCountCopy() {
  105. var ammoCountElement = document.getElementById('ui-current-clip');
  106. if (ammoCountElement && window.getComputedStyle(ammoCountElement).display !== 'none' && parseFloat(window.getComputedStyle(ammoCountElement).opacity) > 0) {
  107. var ammoCount = ammoCountElement.textContent;
  108. ammoCountCopy.textContent = ammoCount;
  109. ammoCountCopy.style.color = ammoCountElement.style.color;
  110. ammoCountCopy.style.display = 'block';
  111. } else {
  112. ammoCountCopy.style.display = 'none';
  113. }
  114. }
  115.  
  116. function updateWeaponNameCopy() {
  117. var equippedWeapon = document.querySelector('.ui-weapon-switch[style*="background-color: rgba(0, 0, 0, 0.4)"], .ui-weapon-switch[style*="opacity: 1"]');
  118. if (equippedWeapon) {
  119. var weaponName = equippedWeapon.querySelector('.ui-weapon-name').textContent;
  120. weaponNameCopy.textContent = weaponName;
  121. weaponNameCopy.style.color = 'white';
  122. weaponNameCopy.style.display = 'block';
  123. } else {
  124. weaponNameCopy.style.display = 'none';
  125. }
  126. }
  127.  
  128. function updateBoostWidthCopy() {
  129. var boostElement = document.getElementById('ui-boost-counter');
  130. if (boostElement && window.getComputedStyle(boostElement).display !== 'none' && parseFloat(window.getComputedStyle(boostElement).opacity) > 0) {
  131. var averageBoostWidth = calculateAverageBoostWidth();
  132. boostWidthCopy.textContent = averageBoostWidth;
  133. boostWidthCopy.style.display = 'block';
  134. } else {
  135. boostWidthCopy.style.display = 'none';
  136. }
  137. }
  138.  
  139. function followCursor(event) {
  140. healthBarWidthCopy.style.left = `${event.clientX - 70}px`;
  141. healthBarWidthCopy.style.top = `${event.clientY + 25}px`;
  142.  
  143. ammoCountCopy.style.left = `${event.clientX + 40}px`;
  144. ammoCountCopy.style.top = `${event.clientY + 25}px`;
  145.  
  146. weaponNameCopy.style.left = `${event.clientX + 40}px`;
  147. weaponNameCopy.style.top = `${event.clientY + 50}px`;
  148.  
  149. boostWidthCopy.style.left = `${event.clientX - 70}px`;
  150. boostWidthCopy.style.top = `${event.clientY + 50}px`;
  151. }
  152.  
  153. document.addEventListener('mousemove', followCursor);
  154.  
  155. healthBarWidthCopy.style.webkitTouchCallout = 'none'; /* iOS Safari */
  156. healthBarWidthCopy.style.webkitUserSelect = 'none'; /* Safari */
  157. healthBarWidthCopy.style.userSelect = 'none'; /* Standard syntax */
  158.  
  159. ammoCountCopy.style.webkitTouchCallout = 'none'; /* iOS Safari */
  160. ammoCountCopy.style.webkitUserSelect = 'none'; /* Safari */
  161. ammoCountCopy.style.userSelect = 'none'; /* Standard syntax */
  162.  
  163. weaponNameCopy.style.webkitTouchCallout = 'none'; /* iOS Safari */
  164. weaponNameCopy.style.webkitUserSelect = 'none'; /* Safari */
  165. weaponNameCopy.style.userSelect = 'none'; /* Standard syntax */
  166.  
  167. boostWidthCopy.style.webkitTouchCallout = 'none'; /* iOS Safari */
  168. boostWidthCopy.style.webkitUserSelect = 'none'; /* Safari */
  169. boostWidthCopy.style.userSelect = 'none'; /* Standard syntax */
  170.  
  171. document.body.appendChild(healthBarWidthCopy);
  172. document.body.appendChild(ammoCountCopy);
  173. document.body.appendChild(weaponNameCopy);
  174. document.body.appendChild(boostWidthCopy);
  175.  
  176. updateHealthBarWidthCopy();
  177. updateAmmoCountCopy();
  178. updateWeaponNameCopy();
  179. updateBoostWidthCopy();
  180.  
  181. var healthObserver = new MutationObserver(updateHealthBarWidthCopy);
  182. var healthTargetNode = document.getElementById('ui-health-actual');
  183. if (healthTargetNode) {
  184. healthObserver.observe(healthTargetNode, { attributes: true, attributeFilter: ['style', 'class'] });
  185. }
  186. if (healthTargetNode && healthTargetNode.parentElement) {
  187. healthObserver.observe(healthTargetNode.parentElement, { attributes: true, attributeFilter: ['style', 'class'] });
  188. }
  189.  
  190. var ammoObserver = new MutationObserver(updateAmmoCountCopy);
  191. var ammoTargetNode = document.getElementById('ui-current-clip');
  192. if (ammoTargetNode) {
  193. ammoObserver.observe(ammoTargetNode, { attributes: true, childList: true, subtree: true });
  194. }
  195.  
  196. var weaponObserver = new MutationObserver(updateWeaponNameCopy);
  197. var weaponTargetNodes = document.querySelectorAll('.ui-weapon-switch');
  198. weaponTargetNodes.forEach(function(node) {
  199. weaponObserver.observe(node, { attributes: true, attributeFilter: ['style', 'class'] });
  200. });
  201.  
  202. var boostObserver = new MutationObserver(updateBoostWidthCopy);
  203. var boostTargetNodes = document.querySelectorAll('#ui-boost-counter .ui-bar-inner');
  204. boostTargetNodes.forEach(function(node) {
  205. boostObserver.observe(node, { attributes: true, attributeFilter: ['style', 'class'] });
  206. });
  207.  
  208. } else {
  209. var healthBarWidthCopy = document.getElementById('health-bar-width-copy');
  210. if (healthBarWidthCopy) {
  211. healthBarWidthCopy.parentNode.removeChild(healthBarWidthCopy);
  212. }
  213.  
  214. var ammoCountCopy = document.getElementById('ammo-count-copy');
  215. if (ammoCountCopy) {
  216. ammoCountCopy.parentNode.removeChild(ammoCountCopy);
  217. }
  218.  
  219. var weaponNameCopy = document.getElementById('weapon-name-copy');
  220. if (weaponNameCopy) {
  221. weaponNameCopy.parentNode.removeChild(weaponNameCopy);
  222. }
  223.  
  224. var boostWidthCopy = document.getElementById('boost-width-copy');
  225. if (boostWidthCopy) {
  226. boostWidthCopy.parentNode.removeChild(boostWidthCopy);
  227. }
  228. }
  229. }
  230.  
  231. toggleUIElementDisplay(true);
  232. showKillCounter();
  233. periodicallyShowKillCounter();
  234. })();