|
1 |
| -"use strict"; |
2 |
| - |
3 |
| -const __DEFAULT_REVIVE_REQUEST = { |
4 |
| - method: "POST", |
5 |
| - relay: true, |
6 |
| - silent: true, |
7 |
| - succeedOnError: true, |
8 |
| -}; |
9 |
| - |
10 |
| -function __requestStigFormat(location, vendor) { |
11 |
| - return (id, name, country, faction, source) => |
12 |
| - new Promise((resolve, reject) => { |
13 |
| - fetchData(location, { |
14 |
| - ...__DEFAULT_REVIVE_REQUEST, |
15 |
| - section: "request", |
16 |
| - body: { tornid: id.toString(), username: name, source: source, vendor, type: "revive" }, |
17 |
| - }) |
18 |
| - .then((response) => { |
19 |
| - if (response.hasOwnProperty("contract")) { |
20 |
| - resolve({ response, contract: response["contract"] }); |
21 |
| - } else { |
22 |
| - reject(response); |
23 |
| - } |
24 |
| - }) |
25 |
| - .catch((reason) => reject(reason)); |
26 |
| - }); |
27 |
| -} |
28 |
| - |
29 |
| -const REVIVE_PROVIDERS = [ |
30 |
| - { |
31 |
| - provider: "nuke", |
32 |
| - name: "Nuke", |
33 |
| - origin: FETCH_PLATFORMS.nukefamily, |
34 |
| - doRequest: (id, name, country, faction, source) => |
35 |
| - new Promise((resolve, reject) => { |
36 |
| - fetchData("nukefamily", { |
37 |
| - ...__DEFAULT_REVIVE_REQUEST, |
38 |
| - section: "api/revive-request", |
39 |
| - body: { |
40 |
| - torn_player_id: id, |
41 |
| - torn_player_name: name, |
42 |
| - torn_player_country: country, |
43 |
| - app_info: source, |
44 |
| - }, |
45 |
| - }) |
46 |
| - .then((response) => { |
47 |
| - if (response.success) resolve({ response }); |
48 |
| - else reject(response); |
49 |
| - }) |
50 |
| - .catch((reason) => reject(reason)); |
51 |
| - }), |
52 |
| - price: { |
53 |
| - money: 1_800_000, |
54 |
| - xanax: 2, |
55 |
| - }, |
56 |
| - }, |
57 |
| - { |
58 |
| - provider: "uhc", |
59 |
| - name: "UHC", |
60 |
| - origin: FETCH_PLATFORMS.uhc, |
61 |
| - doRequest: (id, name, country, faction, source) => |
62 |
| - new Promise((resolve, reject) => { |
63 |
| - fetchData("uhc", { |
64 |
| - ...__DEFAULT_REVIVE_REQUEST, |
65 |
| - section: "api/request", |
66 |
| - body: { userID: id, userName: name, factionName: faction, source }, |
67 |
| - }) |
68 |
| - .then((response) => { |
69 |
| - if (response.success) resolve({ response }); |
70 |
| - else reject(response); |
71 |
| - }) |
72 |
| - .catch((reason) => reject(reason)); |
73 |
| - }), |
74 |
| - price: { |
75 |
| - money: 1_800_000, |
76 |
| - xanax: 2, |
77 |
| - }, |
78 |
| - }, |
79 |
| - { |
80 |
| - provider: "imperium", |
81 |
| - name: "Imperium", |
82 |
| - origin: FETCH_PLATFORMS.imperium, |
83 |
| - doRequest: (id, name, country, faction, source) => |
84 |
| - new Promise((resolve, reject) => { |
85 |
| - fetchData("imperium", { |
86 |
| - ...__DEFAULT_REVIVE_REQUEST, |
87 |
| - section: "revive", |
88 |
| - body: { userID: id, userName: name, factionName: faction, source }, |
89 |
| - }) |
90 |
| - .then((response) => { |
91 |
| - if (response.success) resolve({ response }); |
92 |
| - else reject(response); |
93 |
| - }) |
94 |
| - .catch((reason) => reject(reason)); |
95 |
| - }), |
96 |
| - price: { |
97 |
| - money: 1_800_000, |
98 |
| - xanax: 2, |
99 |
| - }, |
100 |
| - }, |
101 |
| - { |
102 |
| - provider: "wtf", |
103 |
| - name: "WTF", |
104 |
| - origin: FETCH_PLATFORMS.wtf, |
105 |
| - doRequest: (id, name, country, faction, source) => |
106 |
| - new Promise((resolve, reject) => { |
107 |
| - fetchData("wtf", { |
108 |
| - ...__DEFAULT_REVIVE_REQUEST, |
109 |
| - section: "wtfapi/revive", |
110 |
| - body: { userID: id, userName: name, Faction: faction, Country: country, requestChannel: source }, |
111 |
| - }) |
112 |
| - .then((response) => { |
113 |
| - if (response.success) resolve({ response }); |
114 |
| - else reject(response); |
115 |
| - }) |
116 |
| - .catch((reason) => reject(reason)); |
117 |
| - }), |
118 |
| - price: { |
119 |
| - money: 1_800_000, |
120 |
| - xanax: 2, |
121 |
| - }, |
122 |
| - }, |
123 |
| - { |
124 |
| - provider: "hela", |
125 |
| - name: "HeLa", |
126 |
| - origin: FETCH_PLATFORMS.hela, |
127 |
| - doRequest: __requestStigFormat("hela", "HeLa"), |
128 |
| - price: { |
129 |
| - money: 1_800_000, |
130 |
| - xanax: 2, |
131 |
| - }, |
132 |
| - }, |
133 |
| - { |
134 |
| - provider: "shadow_healers", |
135 |
| - name: "Shadow Healers", |
136 |
| - origin: FETCH_PLATFORMS.shadow_healers, |
137 |
| - doRequest: __requestStigFormat("shadow_healers", "Shadow Healers"), |
138 |
| - price: { |
139 |
| - money: 1_800_000, |
140 |
| - xanax: 2, |
141 |
| - }, |
142 |
| - }, |
143 |
| - { |
144 |
| - provider: "who", |
145 |
| - name: "The Wolverines", |
146 |
| - origin: FETCH_PLATFORMS.who, |
147 |
| - doRequest: __requestStigFormat("who", "The Wolverines"), |
148 |
| - price: { |
149 |
| - money: 1_000_000, |
150 |
| - xanax: 1, |
151 |
| - }, |
152 |
| - }, |
153 |
| -]; |
154 |
| - |
155 |
| -function doRequestRevive(id, name, country, faction) { |
156 |
| - const source = `TornTools v${chrome.runtime.getManifest().version}`; |
157 |
| - |
158 |
| - const providerName = settings.pages.global.reviveProvider || ""; |
159 |
| - const provider = REVIVE_PROVIDERS.find((p) => p.provider === providerName); |
160 |
| - if (!provider) throw new Error(`Revive provider '${providerName}' not found.`); |
161 |
| - |
162 |
| - return provider |
163 |
| - .doRequest(id, name, country, faction, source) |
164 |
| - .then(({ response, contract }) => ({ response, contract, provider })) |
165 |
| - .catch((response) => ({ response, provider })); |
166 |
| -} |
167 |
| - |
168 |
| -function calculateRevivePrice({ price }) { |
169 |
| - const parts = []; |
170 |
| - |
171 |
| - if (price?.money) parts.push(formatNumber(price.money, { currency: true, shorten: 3 })); |
172 |
| - if (price?.xanax) parts.push(`${price.xanax} xan`); |
173 |
| - |
174 |
| - return parts.length > 0 ? parts.join(" or ") : "unknown"; |
175 |
| -} |
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const __DEFAULT_REVIVE_REQUEST = { |
| 4 | + method: "POST", |
| 5 | + relay: true, |
| 6 | + silent: true, |
| 7 | + succeedOnError: true, |
| 8 | +}; |
| 9 | + |
| 10 | +function __requestStigFormat(vendor) { |
| 11 | + return (id, name, country, faction, source) => |
| 12 | + new Promise((resolve, reject) => { |
| 13 | + fetchData("stig", { |
| 14 | + ...__DEFAULT_REVIVE_REQUEST, |
| 15 | + section: "request", |
| 16 | + body: { tornid: id.toString(), username: name, source: source, vendor, type: "revive" }, |
| 17 | + }) |
| 18 | + .then((response) => { |
| 19 | + if (response.hasOwnProperty("contract")) { |
| 20 | + resolve({ response, contract: response["contract"] }); |
| 21 | + } else { |
| 22 | + reject(response); |
| 23 | + } |
| 24 | + }) |
| 25 | + .catch((reason) => reject(reason)); |
| 26 | + }); |
| 27 | +} |
| 28 | + |
| 29 | +const REVIVE_PROVIDERS = [ |
| 30 | + { |
| 31 | + provider: "nuke", |
| 32 | + name: "Nuke", |
| 33 | + origin: FETCH_PLATFORMS.nukefamily, |
| 34 | + doRequest: (id, name, country, faction, source) => |
| 35 | + new Promise((resolve, reject) => { |
| 36 | + fetchData("nukefamily", { |
| 37 | + ...__DEFAULT_REVIVE_REQUEST, |
| 38 | + section: "api/revive-request", |
| 39 | + body: { |
| 40 | + torn_player_id: id, |
| 41 | + torn_player_name: name, |
| 42 | + torn_player_country: country, |
| 43 | + app_info: source, |
| 44 | + }, |
| 45 | + }) |
| 46 | + .then((response) => { |
| 47 | + if (response.success) resolve({ response }); |
| 48 | + else reject(response); |
| 49 | + }) |
| 50 | + .catch((reason) => reject(reason)); |
| 51 | + }), |
| 52 | + price: { |
| 53 | + money: 1_800_000, |
| 54 | + xanax: 2, |
| 55 | + }, |
| 56 | + }, |
| 57 | + { |
| 58 | + provider: "uhc", |
| 59 | + name: "UHC", |
| 60 | + origin: FETCH_PLATFORMS.uhc, |
| 61 | + doRequest: (id, name, country, faction, source) => |
| 62 | + new Promise((resolve, reject) => { |
| 63 | + fetchData("uhc", { |
| 64 | + ...__DEFAULT_REVIVE_REQUEST, |
| 65 | + section: "api/request", |
| 66 | + body: { userID: id, userName: name, factionName: faction, source }, |
| 67 | + }) |
| 68 | + .then((response) => { |
| 69 | + if (response.success) resolve({ response }); |
| 70 | + else reject(response); |
| 71 | + }) |
| 72 | + .catch((reason) => reject(reason)); |
| 73 | + }), |
| 74 | + price: { |
| 75 | + money: 1_800_000, |
| 76 | + xanax: 2, |
| 77 | + }, |
| 78 | + }, |
| 79 | + { |
| 80 | + provider: "imperium", |
| 81 | + name: "Imperium", |
| 82 | + origin: FETCH_PLATFORMS.imperium, |
| 83 | + doRequest: (id, name, country, faction, source) => |
| 84 | + new Promise((resolve, reject) => { |
| 85 | + fetchData("imperium", { |
| 86 | + ...__DEFAULT_REVIVE_REQUEST, |
| 87 | + section: "revive", |
| 88 | + body: { userID: id, userName: name, factionName: faction, source }, |
| 89 | + }) |
| 90 | + .then((response) => { |
| 91 | + if (response.success) resolve({ response }); |
| 92 | + else reject(response); |
| 93 | + }) |
| 94 | + .catch((reason) => reject(reason)); |
| 95 | + }), |
| 96 | + price: { |
| 97 | + money: 1_800_000, |
| 98 | + xanax: 2, |
| 99 | + }, |
| 100 | + }, |
| 101 | + { |
| 102 | + provider: "wtf", |
| 103 | + name: "WTF", |
| 104 | + origin: FETCH_PLATFORMS.wtf, |
| 105 | + doRequest: (id, name, country, faction, source) => |
| 106 | + new Promise((resolve, reject) => { |
| 107 | + fetchData("wtf", { |
| 108 | + ...__DEFAULT_REVIVE_REQUEST, |
| 109 | + section: "wtfapi/revive", |
| 110 | + body: { userID: id, userName: name, Faction: faction, Country: country, requestChannel: source }, |
| 111 | + }) |
| 112 | + .then((response) => { |
| 113 | + if (response.success) resolve({ response }); |
| 114 | + else reject(response); |
| 115 | + }) |
| 116 | + .catch((reason) => reject(reason)); |
| 117 | + }), |
| 118 | + price: { |
| 119 | + money: 1_800_000, |
| 120 | + xanax: 2, |
| 121 | + }, |
| 122 | + }, |
| 123 | + { |
| 124 | + provider: "hela", |
| 125 | + name: "HeLa", |
| 126 | + origin: FETCH_PLATFORMS.stig, |
| 127 | + doRequest: __requestStigFormat("HeLa"), |
| 128 | + price: { |
| 129 | + money: 1_800_000, |
| 130 | + xanax: 2, |
| 131 | + }, |
| 132 | + }, |
| 133 | + { |
| 134 | + provider: "shadow_healers", |
| 135 | + name: "Shadow Healers", |
| 136 | + origin: FETCH_PLATFORMS.stig, |
| 137 | + doRequest: __requestStigFormat("Shadow Healers"), |
| 138 | + price: { |
| 139 | + money: 1_800_000, |
| 140 | + xanax: 2, |
| 141 | + }, |
| 142 | + }, |
| 143 | + { |
| 144 | + provider: "who", |
| 145 | + name: "The Wolverines", |
| 146 | + origin: FETCH_PLATFORMS.stig, |
| 147 | + doRequest: __requestStigFormat("The Wolverines"), |
| 148 | + price: { |
| 149 | + money: 1_000_000, |
| 150 | + xanax: 1, |
| 151 | + }, |
| 152 | + }, |
| 153 | +]; |
| 154 | + |
| 155 | +function doRequestRevive(id, name, country, faction) { |
| 156 | + const source = `TornTools v${chrome.runtime.getManifest().version}`; |
| 157 | + |
| 158 | + const providerName = settings.pages.global.reviveProvider || ""; |
| 159 | + const provider = REVIVE_PROVIDERS.find((p) => p.provider === providerName); |
| 160 | + if (!provider) throw new Error(`Revive provider '${providerName}' not found.`); |
| 161 | + |
| 162 | + return provider |
| 163 | + .doRequest(id, name, country, faction, source) |
| 164 | + .then(({ response, contract }) => ({ response, contract, provider })) |
| 165 | + .catch((response) => ({ response, provider })); |
| 166 | +} |
| 167 | + |
| 168 | +function calculateRevivePrice({ price }) { |
| 169 | + const parts = []; |
| 170 | + |
| 171 | + if (price?.money) parts.push(formatNumber(price.money, { currency: true, shorten: 3 })); |
| 172 | + if (price?.xanax) parts.push(`${price.xanax} xan`); |
| 173 | + |
| 174 | + return parts.length > 0 ? parts.join(" or ") : "unknown"; |
| 175 | +} |
0 commit comments