SS同盟信息增强

自动计算积分并显示在用户资料页面

目前为 2022-07-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name SS同盟信息增强
  3. // @namespace 3BBBC94E5807338FF2A3A63A253333D049DECC00
  4. // @version 0.2.1
  5. // @description 自动计算积分并显示在用户资料页面
  6. // @author syd
  7. // @license 2022 up to now, syd All Rights Reserved
  8. // @match https://sstm.moe/profile/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=sstm.moe
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. const parseData = () => {
  14. let data = {
  15. content: 0,
  16. jc: undefined,
  17. luck: undefined,
  18. };
  19. const parseNumber = (num_str) => {
  20. return parseFloat(num_str.replaceAll(/[^\d\.\-]/g, ""));
  21. };
  22. let content_node = document.querySelector("#elProfileStats > ul > li");
  23. data.content = content_node ? parseNumber(content_node.innerText) : 0;
  24. for (const line of document.querySelectorAll(
  25. ".ipsDataItem_main:not(.ipsType_break)"
  26. )) {
  27. if (line.innerText.endsWith("J")) {
  28. data.jc = parseNumber(line.innerText);
  29. } else if (line.innerText.endsWith("F")) {
  30. data.luck = parseNumber(line.innerText);
  31. }
  32. }
  33. return data;
  34. };
  35.  
  36. const calculatePoints = (data) => {
  37. let points_node = document.createElement("li");
  38. points_node.setAttribute("class", "ipsDataItem");
  39. const points = parseInt(data.content * 0.3 + data.luck * 10 + data.jc * 0.03);
  40. points_node.innerHTML = `<span class="ipsDataItem_generic ipsDataItem_size3 ipsType_break"><strong>积分</strong></span>
  41. <span class="ipsDataItem_main ipsType_break" style="color: red;"><strong>${points}</strong></span>`;
  42. let username = "";
  43. for (const title of document.querySelectorAll(".ipsPageHead_barText")) {
  44. username =
  45. username === "" ? title.innerText : `${title.innerText} ${username}`;
  46. }
  47. console.info(`[SSTM] ${username}`, data, `=> ${points}`);
  48. let profile_node = document.querySelector(".cProfileFields");
  49. let first_line_node = profile_node.querySelector(".ipsDataItem");
  50. if (first_line_node) {
  51. profile_node.insertBefore(points_node, first_line_node);
  52. } else {
  53. profile_node.append(points_node);
  54. }
  55. };
  56.  
  57. (function () {
  58. "use strict";
  59. let timer = setInterval(() => {
  60. const result = parseData();
  61. if (result.jc !== undefined) {
  62. clearInterval(timer);
  63. calculatePoints(result);
  64. }
  65. }, 1000);
  66. })();

QingJ © 2025

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