Greasy Fork

Greasy Fork is available in English.

HPS Counter Bloxd.io

Bloxd.io HPS Counter

当前为 2024-09-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         HPS Counter Bloxd.io
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Bloxd.io HPS Counter
// @author       Orazix
// @match        https://bloxd.io/
// @license MIT
// @copyright 2024, Orazix (https://openuserjs.org/users/Orazix)
// ==/UserScript==

(function () {
  var container = document.createElement('div');
  container.style.position = 'fixed';
  container.style.bottom = '10px';
  container.style.left = '10px';
  container.style.backgroundColor = 'transparent';
  container.style.color = 'white';
  container.style.padding = '5px';
  container.style.fontFamily = 'Arial';
  container.style.fontSize = '14px';
  container.style.zIndex = '9999';

  var hpsButton = document.createElement('div');
  hpsButton.style.position = 'fixed';
  hpsButton.style.top = '10px';
  hpsButton.style.left = '33.33%';
  hpsButton.style.transform = 'translateX(-50%)';
  hpsButton.style.backgroundColor = 'black';
  hpsButton.style.color = 'white';
  hpsButton.style.padding = '5px';
  hpsButton.style.fontFamily = 'Arial';
  hpsButton.style.fontSize = '14px';
  hpsButton.style.zIndex = '9999';
  hpsButton.textContent = '';

  var hpsLabel = document.createElement('span');
  hpsLabel.textContent = 'HPS: ';
  var hpsValue = document.createElement('span');
  hpsValue.textContent = '0';

  hpsButton.appendChild(hpsLabel);
  hpsButton.appendChild(hpsValue);
  document.body.appendChild(hpsButton);

  var dphButton = document.createElement('div');
  dphButton.style.position = 'fixed';
  dphButton.style.top = '10px';
  dphButton.style.left = '50%';
  dphButton.style.transform = 'translateX(-50%)';
  dphButton.style.backgroundColor = 'black';
  dphButton.style.color = 'white';
  dphButton.style.padding = '5px';
  dphButton.style.fontFamily = 'Arial';
  dphButton.style.fontSize = '14px';
  dphButton.style.zIndex = '9999';
  dphButton.textContent = '';

  var dphLabel = document.createElement('span');
  dphLabel.textContent = 'DPHPS: ';
  var dphValue = document.createElement('span');
  dphValue.textContent = '0';

  dphButton.appendChild(dphLabel);
  dphButton.appendChild(dphValue);
  document.body.appendChild(dphButton);

  var dpsButton = document.createElement('div');
  dpsButton.style.position = 'fixed';
  dpsButton.style.top = '10px';
  dpsButton.style.left = '66.66%';
  dpsButton.style.transform = 'translateX(-50%)';
  dpsButton.style.backgroundColor = 'black';
  dpsButton.style.color = 'white';
  dpsButton.style.padding = '5px';
  dpsButton.style.fontFamily = 'Arial';
  dpsButton.style.fontSize = '14px';
  dpsButton.style.zIndex = '9999';
  dpsButton.textContent = '';

  var dpsLabel = document.createElement('span');
  dpsLabel.textContent = 'DPS: ';
  var dpsValue = document.createElement('span');
  dpsValue.textContent = '0';

  dpsButton.appendChild(dpsLabel);
  dpsButton.appendChild(dpsValue);
  document.body.appendChild(dpsButton);

  var damageTimes = [];
  var damages = [];

  var previousHealth = 100;

  // Listen for the Ctrl key press
  document.addEventListener('keydown', (event) => {
    if (event.key === "Delete") {
      const targetNode = document.getElementsByClassName('BottomScreenStatBarText SmallTextBold')[0];

      // Create an observer instance linked to the callback function
      const observer = new MutationObserver((mutationsList) => {
        for (const mutation of mutationsList) {
          if (mutation.type === 'characterData' || mutation.type === 'childList') {
            let texts = targetNode.textContent;
            let damage_taken = parseInt(texts.trim().split("/"));
            if (previousHealth === 100 || damage_taken !== previousHealth) {

              console.log(previousHealth);
              console.log(damage_taken);
              if (previousHealth > damage_taken) {
                damages.push(previousHealth - damage_taken)
              };
              previousHealth = damage_taken;
              countHit();

            };
            console.log(damages);
          }
        }
      });

      // Start observing the target node for configured mutations
      observer.observe(targetNode, {
        characterData: true,
        childList: true,
        subtree: true
      });
      console.log("started");
      hpsButton.style.backgroundColor = "green";
      dphButton.style.backgroundColor = "green";
      dpsButton.style.backgroundColor = "green";
    }
  });

  function countHit() {
    var currentTime1 = new Date().getTime();
    damageTimes.push(currentTime1);
    updateHPS();
  }

  function updateHPS() {
    var currentTime1 = new Date().getTime();
    var oneSecondAgo1 = currentTime1 - 1000;
    var count1 = 0;
    var count2 = 0;

    for (var i = damageTimes.length - 1; i >= 0; i--) {
      if (damageTimes[i] >= oneSecondAgo1) {
        count1++;
      }
      else {
        break;
      }
    }
    if (damageTimes[damageTimes.length - 1] - damageTimes[damageTimes.length - 2] >= 1000) {
      damages = [damages[damages.length - 1]];
    }

    for (let e of damages) {
      count2 += e;
    };

    hpsValue.textContent = count1;
    dphValue.textContent = Math.round(count2 / (damages.length + 1))
    dpsValue.textContent = count2;

    if (count1 >= 6 && count1 < 8) {
      hpsButton.style.backgroundColor = "orange";
    }
    else if (count1 >= 8) {
      hpsButton.style.backgroundColor = "red";
    }
    else if (count1 < 6) {
      hpsButton.style.backgroundColor = "green";
    }
  }

  function resetHitCount() {
    damageTimes = [];
    damages = [];
    updateHPS();
  }
})();