Skip to content

Commit ca0c676

Browse files
More accurate/useful end time calculation for OC2 countdown in sidebar. (#842)
Torn's ready_at value corresponds to the planning finish time for currently joined members. If the OC is partially filled ready_at will not provide an accurate end time (i.e. when it will initiate). Update the logic to account for empty slots in the OC. Co-authored-by: Phoenix [85185] <[email protected]>
1 parent e942b6a commit ca0c676

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

extension/changelog.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
{ "message": "Migrate faction stakeouts over to API V2.", "contributor": "DeKleineKobini" },
2222
{ "message": "Migrate faction last action over to API V2.", "contributor": "DeKleineKobini" },
2323
{ "message": "Make icons in the popup clickable to open their corresponding pages.", "contributor": "Hashibee" },
24-
{ "message": "Show some more networth types in live networth.", "contributor": "DeKleineKobini" }
24+
{ "message": "Show some more networth types in live networth.", "contributor": "DeKleineKobini" },
25+
{ "message": "More accurate/useful end time for OC2 countdown in sidebar", "contributor": "Phoenix" }
2526
],
2627
"removed": []
2728
}

extension/scripts/features/oc2-time/ttOC2Time.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,29 @@
6060

6161
function buildTimeLeftElement() {
6262
const timeLeftElement = document.newElement({ type: "span", class: "countdown" });
63+
const now = Date.now();
64+
let readyAt;
65+
// Torn's ready_at value corresponds to the planning finish time for currently joined members
66+
// If the OC is partially filled it will not provide an accurate end time (i.e. when it will initiate)
67+
68+
// Count the missing members
69+
let missingMembers = 0;
70+
for (const slot of userdata.organizedCrime.slots) {
71+
if (slot.user_id === null) {
72+
missingMembers += 1;
73+
}
74+
}
75+
76+
// Add 24 hours for every missing member
77+
// The end result is that this now provides the earliest projected end/initiation time
78+
if (missingMembers > 0) {
79+
const missingTime = 24 * 60 * 60 * missingMembers;
80+
readyAt = Math.max((userdata.organizedCrime.ready_at + missingTime) * 1000, now + missingTime * 1000);
81+
} else {
82+
readyAt = userdata.organizedCrime.ready_at * 1000;
83+
}
6384

64-
const readyAt = userdata.organizedCrime.ready_at * 1000;
65-
const timeLeft = readyAt - Date.now();
85+
const timeLeft = readyAt - now;
6686

6787
if (timeLeft <= TO_MILLIS.HOURS * 8) timeLeftElement.classList.add("short");
6888
else if (timeLeft <= TO_MILLIS.HOURS * 12) timeLeftElement.classList.add("medium");

extension/scripts/global/team.js

+7
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ const TEAM = [
238238
torn: 2303184,
239239
color: "#6ACF65",
240240
},
241+
{
242+
name: "Phoenix",
243+
title: "Developer",
244+
core: false,
245+
torn: 85185,
246+
color: "#085185",
247+
},
241248
];
242249

243250
const CONTRIBUTORS = TEAM.filter(({ title, color }) => title.includes("Developer") || color).reduce(

0 commit comments

Comments
 (0)