黑猫云按键统计当月网络用量

增加一个按键统计当月流量使用量

  1. // ==UserScript==
  2. // @name 黑猫云按键统计当月网络用量
  3. // @namespace http://shenhaisu.cc/
  4. // @version 1.1
  5. // @description 增加一个按键统计当月流量使用量
  6. // @author ShenHaiSu_Kim
  7. // @match https://yun.hmvps.cn/servicedetail?id=*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=hmvps.cn
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. let getStartTime = () => document.querySelectorAll("#startingTime")[0].value.substring(0, 8) + "01";
  15. let getEndTime = () => document.querySelector("input#endTime").value;
  16. let machineID = location.href.match(/id=(\d+)/)[1];
  17. let baseURL = "https://yun.hmvps.cn/host/trafficusage?id="
  18.  
  19. let targetParentNode = document.querySelector("#dosage > .row.d-flex.align-items-center");
  20. let buttonNode = Object.assign(document.createElement("button"), {
  21. innerText: "查询当月流量",
  22. type: "button",
  23. className: "btn btn-success btn-sm col-md-2",
  24. style: "font-size: 14px;"
  25. });
  26. let infoSpan = Object.assign(document.createElement("span"), {
  27. innerText: "等待查询...",
  28. className: "col-md-2",
  29. style: "font-size: 14px;line-height: 29.7px;"
  30. });
  31.  
  32.  
  33. buttonNode.addEventListener("click", function (event) {
  34. infoSpan.innerText = "请求已发送...";
  35. fetch(baseURL + machineID + "&start=" + getStartTime() + "&end=" + getEndTime())
  36. .then(res => res.json())
  37. .then(data => {
  38. let totalCount = 0;
  39. data.data.forEach(item => { totalCount += item.in + item.out });
  40. infoSpan.innerText = totalCount.toFixed(2).toString() + "GB";
  41. })
  42. })
  43. document.querySelector("#usedLi").addEventListener("click", function (event) {
  44. if (targetParentNode.querySelectorAll("button").length == 1) return;
  45. targetParentNode.appendChild(buttonNode);
  46. targetParentNode.appendChild(infoSpan);
  47. })
  48. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址