|
17 | 17 | );
|
18 | 18 |
|
19 | 19 | function initialise() {
|
20 |
| - if (!isOwnCompany) |
| 20 | + if (!isOwnCompany) { |
21 | 21 | CUSTOM_LISTENERS[EVENT_CHANNELS.COMPANY_EMPLOYEES_PAGE].push(() => {
|
22 | 22 | if (!feature.enabled() || !settings.pages.companies.idBesideCompanyName) return;
|
23 | 23 |
|
24 | 24 | addID();
|
25 | 25 | });
|
| 26 | + } |
26 | 27 | }
|
27 | 28 |
|
28 | 29 | async function addID() {
|
29 | 30 | if (document.getElementById("tt-company-id")) return; // Element has already been added - second check in-case feature reinjects
|
30 |
| - const selector = isOwnCompany ? "div.company-wrap > div.title-black" : "div.company-details-wrap > div.company-details > div.title-black"; |
31 |
| - const [id, container] = await Promise.all([getCompanyID(), requireElement(selector)]); |
| 31 | + |
| 32 | + const container = await requireElement( |
| 33 | + isOwnCompany ? "div.company-wrap > div.title-black" : "div.company-details-wrap > div.company-details > div.title-black" |
| 34 | + ); |
| 35 | + |
| 36 | + const id = await readCompanyDetails(); |
32 | 37 | if (!id) throw new Error("Company ID could not be found.");
|
33 |
| - const span = document.newElement({ type: "span", text: ` [${id}]`, id: "tt-company-id" }); |
34 |
| - container.appendChild(span); |
| 38 | + |
| 39 | + container.appendChild(document.newElement({ type: "span", text: ` [${id}]`, id: "tt-company-id" })); |
35 | 40 | }
|
36 | 41 |
|
37 | 42 | function removeID() {
|
38 | 43 | document.findAll("#tt-company-id").forEach((element) => element.remove());
|
39 | 44 | }
|
40 |
| - |
41 |
| - async function getCompanyID() { |
42 |
| - if (isOwnCompany) { |
43 |
| - if (userdata.job.company_id) return userdata.job.company_id; |
44 |
| - const userID = userdata.player_id; |
45 |
| - if (!userID) return null; // ID could not be found |
46 |
| - return await getCompanyIDFromUser(userID); |
47 |
| - } |
48 |
| - |
49 |
| - const hashparams = getHashParameters(); |
50 |
| - |
51 |
| - if (isIntNumber(hashparams.get("ID"))) return parseInt(hashparams.get("ID")); |
52 |
| - if (isIntNumber(hashparams.get("userID"))) return await getCompanyIDFromUser(parseInt(hashparams.get("userID"))); |
53 |
| - |
54 |
| - return null; // ID could not be found |
55 |
| - |
56 |
| - async function getCompanyIDFromUser(userID) { |
57 |
| - const cached = ttCache.get("company-id", userID); |
58 |
| - if (cached) return cached; |
59 |
| - const data = await fetchData("torn", { section: "user", selections: ["profile"], id: userID }); |
60 |
| - const companyID = data.job.company_id; |
61 |
| - ttCache.set({ [userID]: companyID }, 3.5 * TO_MILLIS.DAYS, "company-id"); |
62 |
| - return companyID; |
63 |
| - } |
64 |
| - } |
65 | 45 | })();
|
0 commit comments