|
13 | 13 | const GREEN_ARROW = chrome.runtime.getURL("resources/images/svg-icons/green-arrow.svg");
|
14 | 14 | const RED_ARROW = chrome.runtime.getURL("resources/images/svg-icons/red-arrow.svg");
|
15 | 15 |
|
| 16 | + let scoutLock = false; |
| 17 | + |
16 | 18 | const feature = featureManager.registerFeature(
|
17 | 19 | "FF Scouter Gauge",
|
18 | 20 | "ff-scouter",
|
|
38 | 40 | }
|
39 | 41 |
|
40 | 42 | async function triggerGauge() {
|
| 43 | + if (scoutLock) return; |
| 44 | + scoutLock = true; |
| 45 | + |
41 | 46 | const honorBars = [...document.findAll(".honor-text-wrap")];
|
42 | 47 | if (honorBars) {
|
43 |
| - applyGauge(honorBars); |
| 48 | + applyGauge(honorBars).finally(() => (scoutLock = false)); |
44 | 49 | } else {
|
45 | 50 | let selector;
|
46 | 51 |
|
|
72 | 77 | return;
|
73 | 78 | }
|
74 | 79 |
|
75 |
| - applyGauge([...document.findAll(selector)]); |
| 80 | + applyGauge([...document.findAll(selector)]).finally(() => (scoutLock = false)); |
76 | 81 | }
|
77 | 82 | }
|
78 | 83 |
|
|
81 | 86 | .filter((element) => !element.classList.contains("tt-ff-scouter-indicator"))
|
82 | 87 | .map((element) => ({ element, id: extractPlayerId(element) }))
|
83 | 88 | .filter(({ id }) => !!id);
|
84 |
| - if (elements.length === 0) return; |
85 |
| - |
86 |
| - scoutFFGroup(elements.map(({ id }) => id)).then((scouts) => { |
87 |
| - if (!scouts.status) return; |
| 89 | + if (elements.length === 0) return Promise.resolve(); |
88 | 90 |
|
89 |
| - for (const { element, id } of elements) { |
90 |
| - element.classList.add("tt-ff-scouter-indicator"); |
91 |
| - if (!element.classList.contains("indicator-lines")) { |
92 |
| - element.classList.remove("small", "big"); |
93 |
| - element.classList.add("indicator-lines"); |
94 |
| - element.style.setProperty("--arrow-width", "20px"); |
| 91 | + return new Promise((resolve) => { |
| 92 | + scoutFFGroup(elements.map(({ id }) => id)).then((scouts) => { |
| 93 | + if (!scouts.status) { |
| 94 | + resolve(); |
| 95 | + return; |
95 | 96 | }
|
96 | 97 |
|
97 |
| - const ff = scouts.results[id]?.result?.value; |
98 |
| - if (ff) { |
99 |
| - const percent = convertFFToPercentage(ff); |
100 |
| - element.style.setProperty("--band-percent", percent); |
101 |
| - |
102 |
| - element.find(".tt-ff-scouter-arrow")?.remove(); |
103 |
| - |
104 |
| - let arrow; |
105 |
| - if (percent < 33) { |
106 |
| - arrow = BLUE_ARROW; |
107 |
| - } else if (percent < 66) { |
108 |
| - arrow = GREEN_ARROW; |
109 |
| - } else { |
110 |
| - arrow = RED_ARROW; |
| 98 | + for (const { element, id } of elements) { |
| 99 | + element.classList.add("tt-ff-scouter-indicator"); |
| 100 | + if (!element.classList.contains("indicator-lines")) { |
| 101 | + element.classList.remove("small", "big"); |
| 102 | + element.classList.add("indicator-lines"); |
| 103 | + element.style.setProperty("--arrow-width", "20px"); |
111 | 104 | }
|
112 | 105 |
|
113 |
| - element.appendChild( |
114 |
| - document.newElement({ |
115 |
| - type: "img", |
116 |
| - class: "tt-ff-scouter-arrow", |
117 |
| - attributes: { src: arrow }, |
118 |
| - }) |
119 |
| - ); |
| 106 | + const ff = scouts.results[id]?.result?.value; |
| 107 | + if (ff) { |
| 108 | + const percent = convertFFToPercentage(ff); |
| 109 | + element.style.setProperty("--band-percent", percent); |
| 110 | + |
| 111 | + element.find(".tt-ff-scouter-arrow")?.remove(); |
| 112 | + |
| 113 | + let arrow; |
| 114 | + if (percent < 33) { |
| 115 | + arrow = BLUE_ARROW; |
| 116 | + } else if (percent < 66) { |
| 117 | + arrow = GREEN_ARROW; |
| 118 | + } else { |
| 119 | + arrow = RED_ARROW; |
| 120 | + } |
| 121 | + |
| 122 | + element.appendChild( |
| 123 | + document.newElement({ |
| 124 | + type: "img", |
| 125 | + class: "tt-ff-scouter-arrow", |
| 126 | + attributes: { src: arrow }, |
| 127 | + }) |
| 128 | + ); |
| 129 | + } |
120 | 130 | }
|
121 |
| - } |
| 131 | + |
| 132 | + resolve(); |
| 133 | + }); |
122 | 134 | });
|
123 | 135 | }
|
124 | 136 |
|
|
0 commit comments