Repository navigation
Expand file tree
/
Copy pathprogress.js
More file actions
180 lines (143 loc) · 4.94 KB
/
Copy pathprogress.js
File metadata and controls
180 lines (143 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const AftershiftProgress = (() => {
const endingScores = {
1: {
"ENDING: FULL ATTRIBUTION": 6,
"ENDING: ROOT CAUSE": 5,
"ENDING: CONTAINMENT": 4,
"ENDING: SOMETHING REMAINS": 3,
"ENDING: LOCKED DOWN": 2,
"ENDING: THE BREACH": 1
},
2: {
"ENDING: INSIDE ACCESS": 6,
"ENDING: CONTAINED AGAIN": 5,
"ENDING: QUIET COVER-UP": 3,
"ENDING: THE GHOST REMAINS": 2,
"ENDING: FALSE POSITIVE": 1
},
3: {
"ENDING: DEAD CHANNEL": 6,
"ENDING: TRUST ANCHOR": 5,
"ENDING: SILENCE": 4,
"ENDING: NO SIGNAL": 2,
"ENDING: FALSE DIRECTIVE": 1
},
4: {
"ENDING: LIGHTS ON": 6,
"ENDING: CONTROLLED BLACKOUT": 5,
"ENDING: MANUAL SURVIVAL": 4,
"ENDING: PARTIAL RESTORE": 3,
"ENDING: DARK FLOOR": 2,
"ENDING: AUTOMATED FAILURE": 1
},
5: {
"ENDING: FIRST LIGHT": 7,
"ENDING: CLEAN BREAK": 6,
"ENDING: BURN NOTICE": 4,
"ENDING: CLOSED LOOP": 3,
"ENDING: NIGHTWATCH CONTINUES": 2,
"ENDING: FALSE ATTRIBUTION": 1,
"ENDING: UNFINISHED CASE": 1
}
};
function getChapter() {
const path = window.location.pathname.toLowerCase();
if (path.includes("shift1.html")) return 1;
if (path.includes("shift2.html")) return 2;
if (path.includes("shift3.html")) return 3;
if (path.includes("shift4.html")) return 4;
if (path.includes("shift5.html")) return 5;
return null;
}
function endingKey(chapter) {
return `aftershift_shift${chapter}_best`;
}
function completeKey(chapter) {
return `aftershift_shift${chapter}_complete`;
}
function normalizeEnding(ending) {
return ending.trim().replace(/\s+/g, " ").toUpperCase();
}
function scoreEnding(chapter, ending) {
const normalized = normalizeEnding(ending);
const scores = endingScores[chapter] || {};
return scores[normalized] || 0;
}
function saveEnding(chapter, ending) {
if (!chapter || !ending) return;
const normalized = normalizeEnding(ending);
const oldEnding = localStorage.getItem(endingKey(chapter));
if (
!oldEnding ||
scoreEnding(chapter, normalized) >= scoreEnding(chapter, oldEnding)
) {
localStorage.setItem(endingKey(chapter), normalized);
}
localStorage.setItem(completeKey(chapter), "true");
localStorage.setItem("aftershift_last_completed", String(chapter));
localStorage.setItem("aftershift_campaign_started", "true");
}
function migrateOldSaves() {
const shift2 = localStorage.getItem("aftershift_shift2_best");
const shift3 = localStorage.getItem("aftershift_shift3_best");
if (shift2) {
localStorage.setItem("aftershift_shift1_complete", "true");
if (!localStorage.getItem("aftershift_shift1_best")) {
localStorage.setItem(
"aftershift_shift1_best",
"ENDING: FULL ATTRIBUTION"
);
}
localStorage.setItem("aftershift_shift2_complete", "true");
}
if (shift3) {
localStorage.setItem("aftershift_shift2_complete", "true");
localStorage.setItem("aftershift_shift3_complete", "true");
}
}
function watchEnding() {
const chapter = getChapter();
if (!chapter) return;
const endingTitle = document.getElementById("ending-title");
if (!endingTitle) return;
const observer = new MutationObserver(() => {
const ending = endingTitle.textContent.trim();
if (ending.toUpperCase().startsWith("ENDING:")) {
saveEnding(chapter, ending);
}
});
observer.observe(endingTitle, {
childList: true,
subtree: true,
characterData: true
});
}
function getBestEnding(chapter) {
return localStorage.getItem(endingKey(chapter));
}
function isComplete(chapter) {
return localStorage.getItem(completeKey(chapter)) === "true";
}
function clearCampaign() {
const keys = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key && key.startsWith("aftershift_")) {
keys.push(key);
}
}
keys.forEach(key => localStorage.removeItem(key));
}
migrateOldSaves();
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", watchEnding);
} else {
watchEnding();
}
return {
getBestEnding,
isComplete,
clearCampaign,
saveEnding
};
})();