OC - Prevent Joining Low %

Prevents joining OCs if success rate is too low

目前为 2025-02-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name OC - Prevent Joining Low %
  3. // @namespace Titanic_
  4. // @version 1.2
  5. // @description Prevents joining OCs if success rate is too low
  6. // @author Titanic_ [2968477]
  7. // @license MIT
  8. // @match https://www.torn.com/factions.php?step=your*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // minimum oc level (disables join btn if oc level is below this)
  16. const MIN_LEVEL = 5;
  17.  
  18. // minimum % for each level (default is used if % is undefined)
  19. // default must be set to either Red, Orange or Green
  20. const LEVEL_REQUIREMENTS = {
  21. 7: 75,
  22. 8: 65,
  23. 9: 0,
  24. 10: 0,
  25. default: "Green"
  26. };
  27.  
  28. const COLOR_ORDER = ["Red", "Orange", "Green"];
  29.  
  30. function observe() {
  31. if (!window.location.href.includes("tab=crimes")) return;
  32. clearInterval(window.OCCheckInterval);
  33. window.OCCheckInterval = setInterval(() => {
  34. if (document.querySelector("[class*=joinButton_]")) process();
  35. }, 500);
  36. }
  37.  
  38. function process() {
  39. document.querySelectorAll("#faction-crimes-root div[class*=contentLayer_]:not([data-checked]").forEach(row => {
  40. const ocLevel = parseInt(row.querySelector("span[class*=levelValue_]")?.textContent)
  41. if (!ocLevel) return console.warn("Failed to find OC Level");
  42.  
  43. row.querySelectorAll("[class*=joinButton_]").forEach(btn => {
  44. const wrapper = btn.closest("[class*=wrapper]");
  45. const minSuccessRate = LEVEL_REQUIREMENTS[ocLevel];
  46. const successRate = parseInt(wrapper?.querySelector("[class*=successChance]")?.textContent);
  47.  
  48. if (!successRate) return console.warn("Failed to find OC Success Rate");
  49. btn.disabled = ocLevel < MIN_LEVEL || (minSuccessRate !== undefined
  50. ? successRate < minSuccessRate
  51. : !COLOR_ORDER.slice(COLOR_ORDER.indexOf(LEVEL_REQUIREMENTS.default)).some(c => wrapper.className.includes(c)));
  52. });
  53.  
  54. row.dataset.checked = "checked";
  55. });
  56. }
  57.  
  58. window.addEventListener("hashchange", observe);
  59. observe();
  60. })();