Skip to content

Commit 73bb571

Browse files
Updates to the revive prices. (#830)
* Make revives more generic to call. * Include price of requested revive in displayed message. * Show revive request message for 10 seconds instead of 2.5. * Show revive request prices on the settings page. * Update changelog.
1 parent cfbcc9e commit 73bb571

File tree

9 files changed

+204
-124
lines changed

9 files changed

+204
-124
lines changed

extension/changelog.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
{ "message": "Show an indication when Loot Ranger has not included every NPC in their scheduled attack.", "contributor": "DeKleineKobini" },
3434
{ "message": "Update the core team titles to reflect DeKleineKobini rejoining.", "contributor": "DeKleineKobini" },
3535
{ "message": "Update the missing hint for 'estranged' to include feet.", "contributor": "DeKleineKobini" },
36-
{ "message": "Detect sidebar conditions better for some sidebar features.", "contributor": "DeKleineKobini" }
36+
{ "message": "Detect sidebar conditions better for some sidebar features.", "contributor": "DeKleineKobini" },
37+
{ "message": "Adjust revive request prices to be accurate. Prices are no longer the same for every revive provider.", "contributor": "DeKleineKobini" }
3738
],
3839
"removed": [
3940
{ "message": "Removed bazaar prices from the popup, as they are set to be removed from the API.", "contributor": "DeKleineKobini" },

extension/manifest.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"scripts/global/functions/formatting.js",
1818
"scripts/global/functions/utilities.js",
1919
"scripts/global/functions/api.js",
20+
"scripts/global/functions/api-external.js",
2021
"scripts/global/functions/torn.js",
2122
"scripts/background.js"
2223
]
@@ -97,6 +98,7 @@
9798
"scripts/global/functions/utilities.js",
9899
"scripts/global/functions/torn.js",
99100
"scripts/global/functions/api.js",
101+
"scripts/global/functions/api-external.js",
100102
"scripts/global/featureManager.js",
101103
"scripts/global/elements/checkbox/ttCheckbox.js",
102104
"scripts/global/elements/checkbox-list/ttCheckboxList.js",
@@ -214,7 +216,8 @@
214216
"scripts/global/functions/database.js",
215217
"scripts/global/functions/requires.js",
216218
"scripts/global/functions/utilities.js",
217-
"scripts/global/functions/api.js"
219+
"scripts/global/functions/api.js",
220+
"scripts/global/functions/api-external.js"
218221
],
219222
"run_at": "document_start"
220223
},

extension/pages/popup/popup.html

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ <h1>Stocks</h1>
239239
<script src="../../scripts/global/functions/torn.js"></script>
240240
<script src="../../scripts/global/functions/utilities.js"></script>
241241
<script src="../../scripts/global/functions/api.js"></script>
242+
<script src="../../scripts/global/functions/api-external.js"></script>
242243
<script src="popup.js"></script>
243244
</body>
244245
</html>

extension/pages/settings/settings.html

+2-8
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,8 @@ <h2>
258258
<label for="global-reviveProvider">Show a revive button for</label>
259259
<select id="global-reviveProvider">
260260
<option value="">none</option>
261-
<option value="uhc">UHC</option>
262-
<option value="nuke">NUKE</option>
263-
<option value="imperium">The Imperium</option>
264-
<option value="hela">HeLa</option>
265-
<option value="shadow_healers">Shadow Healers</option>
266-
<option value="wtf">WTF</option>
267-
<option value="who">WHO</option>
268261
</select>
269-
<label class="note" for="global-reviveProvider">Revives always cost $1m or 1 Xanax.</label>
262+
<label class="note" for="global-reviveProvider">Revives price varies per revive provider.</label>
270263
</div>
271264
<div class="option">
272265
<input id="global-pageTitles" type="checkbox" />
@@ -1984,6 +1977,7 @@ <h2>About</h2>
19841977
<script src="../../scripts/global/functions/torn.js"></script>
19851978
<script src="../../scripts/global/functions/utilities.js"></script>
19861979
<script src="../../scripts/global/functions/api.js"></script>
1980+
<script src="../../scripts/global/functions/api-external.js"></script>
19871981
<script src="../../scripts/global/functions/pages.js"></script>
19881982
<script type="module" src="settings.js"></script>
19891983
</body>

extension/pages/settings/settings.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ async function setupPreferences(requireCleanup) {
228228
addSaveDialog();
229229
});
230230

231+
const reviveProviderSelectElement = _preferences.find("#global-reviveProvider");
232+
for (const provider of REVIVE_PROVIDERS) {
233+
reviveProviderSelectElement.appendChild(
234+
document.newElement({
235+
type: "option",
236+
text: `${provider.name} (${calculateRevivePrice(provider)})`,
237+
attributes: { value: provider.provider },
238+
})
239+
);
240+
}
241+
231242
if (getSearchParameters().has("section"))
232243
switchSection(_preferences.find(`#preferences > section > nav ul > li[name="${getSearchParameters().get("section")}"]`));
233244

@@ -500,15 +511,7 @@ async function setupPreferences(requireCleanup) {
500511
const provider = event.target.value;
501512
if (!provider) return;
502513

503-
let origin;
504-
if (provider === "nuke") origin = FETCH_PLATFORMS.nukefamily;
505-
else if (provider === "uhc") origin = FETCH_PLATFORMS.uhc;
506-
else if (provider === "imperium") origin = FETCH_PLATFORMS.imperium;
507-
else if (provider === "hela") origin = FETCH_PLATFORMS.hela;
508-
else if (provider === "shadow_healers") origin = FETCH_PLATFORMS.shadow_healers;
509-
else if (provider === "wtf") origin = FETCH_PLATFORMS.wtf;
510-
else if (provider === "who") origin = FETCH_PLATFORMS.who;
511-
514+
const origin = REVIVE_PROVIDERS.find((p) => p === provider)?.origin;
512515
if (!origin) return;
513516

514517
if (!chrome.permissions) {
@@ -1270,14 +1273,7 @@ async function setupPreferences(requireCleanup) {
12701273

12711274
const reviveProvider = _preferences.find("#global-reviveProvider").value;
12721275
if (reviveProvider) {
1273-
let origin;
1274-
if (reviveProvider === "nuke") origin = FETCH_PLATFORMS.nukefamily;
1275-
else if (reviveProvider === "uhc") origin = FETCH_PLATFORMS.uhc;
1276-
else if (reviveProvider === "imperium") origin = FETCH_PLATFORMS.imperium;
1277-
else if (reviveProvider === "hela") origin = FETCH_PLATFORMS.hela;
1278-
else if (reviveProvider === "shadow_healers") origin = FETCH_PLATFORMS.shadow_healers;
1279-
else if (reviveProvider === "wtf") origin = FETCH_PLATFORMS.wtf;
1280-
else if (reviveProvider === "who") origin = FETCH_PLATFORMS.who;
1276+
const origin = REVIVE_PROVIDERS.find((p) => p === reviveProvider)?.origin;
12811277

12821278
if (origin) origins.push(origin);
12831279
}

extension/pages/targets/targets.html

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ <h2>Stakeouts</h2>
122122
<script src="../../scripts/global/functions/torn.js"></script>
123123
<script src="../../scripts/global/functions/utilities.js"></script>
124124
<script src="../../scripts/global/functions/api.js"></script>
125+
<script src="../../scripts/global/functions/api-external.js"></script>
125126
<script src="../../scripts/global/functions/pages.js"></script>
126127
<script type="module" src="targets.js"></script>
127128
</body>

extension/scripts/background.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (typeof importScripts !== "undefined")
1111
"global/functions/formatting.js",
1212
"global/functions/utilities.js",
1313
"global/functions/api.js",
14+
"global/functions/api-external.js",
1415
"global/functions/torn.js",
1516
]
1617
);

extension/scripts/features/revive-request/ttReviveRequest.js

+5-97
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@
9595
}
9696

9797
async function requestRevive() {
98-
const provider = settings.pages.global.reviveProvider || "";
99-
10098
const details = getUserDetails();
10199
if (details.error) return false; // TODO - Show error message.
102100

@@ -110,103 +108,13 @@
110108
else if (country === "uae") country = "UAE";
111109
else country = capitalizeText(country.replaceAll("-", " "), { everyWord: true });
112110

113-
const source = `TornTools v${chrome.runtime.getManifest().version}`;
114-
115-
if (provider === "nuke") {
116-
const response = await fetchData("nukefamily", {
117-
section: "api/revive-request",
118-
method: "POST",
119-
body: { torn_player_id: id, torn_player_name: name, torn_player_country: country, app_info: source },
120-
relay: true,
121-
silent: true,
122-
succeedOnError: true,
123-
});
124-
125-
if (response.success) {
126-
displayMessage("Revive requested!");
127-
} else {
128-
displayMessage("Failed to request!", true);
129-
button.removeAttribute("disabled");
130-
console.log("TT - Failed to request a revive with Nuke!", response);
131-
}
132-
} else if (provider === "uhc") {
133-
const response = await fetchData("uhc", {
134-
section: "api/request",
135-
method: "POST",
136-
body: { userID: id, userName: name, factionName: faction, source },
137-
relay: true,
138-
silent: true,
139-
succeedOnError: true,
140-
});
141-
142-
if (response.success) {
143-
displayMessage("Revive requested!");
144-
} else {
145-
displayMessage("Failed to request!", true);
146-
button.removeAttribute("disabled");
147-
console.log("TT - Failed to request a revive with UHC!", response);
148-
}
149-
} else if (provider === "imperium") {
150-
const response = await fetchData("imperium", {
151-
section: "revive",
152-
method: "POST",
153-
body: { userID: id, userName: name, factionName: faction, source },
154-
relay: true,
155-
silent: true,
156-
succeedOnError: true,
157-
});
158-
159-
if (response.success) {
160-
displayMessage("Revive requested!");
161-
} else {
162-
displayMessage("Failed to request!", true);
163-
button.removeAttribute("disabled");
164-
console.log("TT - Failed to request a revive with Imperium!", response);
165-
}
166-
} else if (provider === "hela" || provider === "shadow_healers" || provider === "who") {
167-
const providers = { hela: "HeLa", shadow_healers: "Shadow Healers", who: "The Wolverines" };
168-
const response = await fetchData(provider, {
169-
section: "request",
170-
method: "POST",
171-
body: {
172-
tornid: id.toString(),
173-
username: name,
174-
source: source,
175-
vendor: providers[provider],
176-
type: "revive",
177-
},
178-
relay: true,
179-
silent: true,
180-
succeedOnError: true,
181-
});
182-
183-
if (response.hasOwnProperty("contract")) {
184-
displayMessage((response["contract"] ? "Contract " : "") + " Revive requested!");
185-
} else {
111+
doRequestRevive(id, name, country, faction)
112+
.then(({ provider }) => displayMessage(`Revive requested for ${calculateRevivePrice(provider)}!`))
113+
.catch(({ provider, response }) => {
186114
displayMessage("Failed to request!", true);
187115
button.removeAttribute("disabled");
188-
console.log("TT - Failed to request a revive with " + providers[provider] + "!", response);
189-
}
190-
} else if (provider === "wtf") {
191-
const response = await fetchData("wtf", {
192-
section: "wtfapi/revive",
193-
method: "POST",
194-
body: { userID: id, userName: name, Faction: faction, Country: country, requestChannel: source },
195-
relay: true,
196-
silent: true,
197-
succeedOnError: true,
116+
console.log(`TT - Failed to request a revive with ${provider.name}!`, response);
198117
});
199-
200-
if (response.success) {
201-
displayMessage("Revive requested!");
202-
} else {
203-
displayMessage("Failed to request!", true);
204-
button.removeAttribute("disabled");
205-
console.log("TT - Failed to request a revive with WTF!", response);
206-
}
207-
} else {
208-
console.error("There was an attempt to request revives from an non-existing provider.", settings.pages.global.reviveProvider);
209-
}
210118
}
211119

212120
function getSidebar() {
@@ -223,7 +131,7 @@
223131
setTimeout(() => {
224132
element.textContent = "Request Revive";
225133
element.classList.remove("tt-revive-success");
226-
}, 2500);
134+
}, 10 * TO_MILLIS.SECONDS);
227135
}
228136
}
229137

0 commit comments

Comments
 (0)