Skip to content

Commit 204618a

Browse files
committed
Cleanup: More aggressive use of an existing helper function
1 parent 4975f2e commit 204618a

File tree

3 files changed

+32
-49
lines changed

3 files changed

+32
-49
lines changed

src/Reset.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,41 +211,41 @@ export const resetdetails = (input: resetNames) => {
211211
export const updateAutoReset = (i: number) => {
212212
let value = null
213213
if (i === 1) {
214-
value = Number.parseFloat((DOMCacheGetOrSet('prestigeamount') as HTMLInputElement).value) || 0
214+
value = Number.parseFloat(getElementById<HTMLInputElement>('prestigeamount').value) || 0
215215
player.prestigeamount = Math.max(value, 0)
216216
} else if (i === 2) {
217-
value = Number.parseFloat((DOMCacheGetOrSet('transcendamount') as HTMLInputElement).value) || 0
217+
value = Number.parseFloat(getElementById<HTMLInputElement>('transcendamount').value) || 0
218218
player.transcendamount = Math.max(value, 0)
219219
} else if (i === 3) {
220-
value = Number.parseFloat((DOMCacheGetOrSet('reincarnationamount') as HTMLInputElement).value) || 0
220+
value = Number.parseFloat(getElementById<HTMLInputElement>('reincarnationamount').value) || 0
221221
player.reincarnationamount = Math.max(value, 0)
222222
} else if (i === 4) {
223-
value = Math.floor(Number.parseFloat((DOMCacheGetOrSet('ascensionAmount') as HTMLInputElement).value)) || 1
223+
value = Math.floor(Number.parseFloat(getElementById<HTMLInputElement>('ascensionAmount').value)) || 1
224224
player.autoAscendThreshold = Math.max(value, 1)
225225
} else if (i === 5) {
226-
value = Number.parseFloat((DOMCacheGetOrSet('autoAntSacrificeAmount') as HTMLInputElement).value) || 0
226+
value = Number.parseFloat(getElementById<HTMLInputElement>('autoAntSacrificeAmount').value) || 0
227227
player.autoAntSacTimer = Math.max(value, 0)
228228
}
229229
}
230230

231231
export const updateTesseractAutoBuyAmount = () => {
232-
const value = Math.floor(Number.parseFloat((DOMCacheGetOrSet('tesseractAmount') as HTMLInputElement).value)) || 0
232+
const value = Math.floor(Number.parseFloat(getElementById<HTMLInputElement>('tesseractAmount').value)) || 0
233233
player.tesseractAutoBuyerAmount = Math.max(value, 0)
234234
}
235235

236236
export const updateAutoCubesOpens = (i: number) => {
237237
let value = null
238238
if (i === 1) {
239-
value = Number((DOMCacheGetOrSet('cubeOpensInput') as HTMLInputElement).value) || 0
239+
value = Number(getElementById<HTMLInputElement>('cubeOpensInput').value) || 0
240240
player.openCubes = Math.max(Math.min(value, 100), 0)
241241
} else if (i === 2) {
242-
value = Number((DOMCacheGetOrSet('tesseractsOpensInput') as HTMLInputElement).value) || 0
242+
value = Number(getElementById<HTMLInputElement>('tesseractsOpensInput').value) || 0
243243
player.openTesseracts = Math.max(Math.min(value, 100), 0)
244244
} else if (i === 3) {
245-
value = Number((DOMCacheGetOrSet('hypercubesOpensInput') as HTMLInputElement).value) || 0
245+
value = Number(getElementById<HTMLInputElement>('hypercubesOpensInput').value) || 0
246246
player.openHypercubes = Math.max(Math.min(value, 100), 0)
247247
} else if (i === 4) {
248-
value = Number((DOMCacheGetOrSet('platonicCubeOpensInput') as HTMLInputElement).value) || 0
248+
value = Number(getElementById<HTMLInputElement>('platonicCubeOpensInput').value) || 0
249249
player.openPlatonicsCubes = Math.max(Math.min(value, 100), 0)
250250
}
251251
}

src/Synergism.ts

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,8 +2280,7 @@ const loadSynergy = async () => {
22802280
const omit = /e\+/
22812281
let inputd = player.autoChallengeTimer.start
22822282
let inpute = Number(
2283-
(DOMCacheGetOrSet('startAutoChallengeTimerInput') as HTMLInputElement)
2284-
.value
2283+
getElementById<HTMLInputElement>('startAutoChallengeTimerInput').value
22852284
)
22862285
if (inpute !== inputd || isNaN(inpute + inputd)) {
22872286
getElementById<HTMLInputElement>('startAutoChallengeTimerInput')
@@ -2332,7 +2331,7 @@ const loadSynergy = async () => {
23322331

23332332
inputd = player.prestigeamount
23342333
inpute = Number(
2335-
(DOMCacheGetOrSet('prestigeamount') as HTMLInputElement).value
2334+
getElementById<HTMLInputElement>('prestigeamount').value
23362335
)
23372336
if (inpute !== inputd || isNaN(inpute + inputd)) {
23382337
getElementById<HTMLInputElement>('prestigeamount').value = `${player.prestigeamount || blankSave.prestigeamount}`
@@ -2341,7 +2340,7 @@ const loadSynergy = async () => {
23412340
}
23422341
inputd = player.transcendamount
23432342
inpute = Number(
2344-
(DOMCacheGetOrSet('transcendamount') as HTMLInputElement).value
2343+
getElementById<HTMLInputElement>('transcendamount').value
23452344
)
23462345
if (inpute !== inputd || isNaN(inpute + inputd)) {
23472346
getElementById<HTMLInputElement>('transcendamount').value = `${
@@ -2351,7 +2350,7 @@ const loadSynergy = async () => {
23512350
}
23522351
inputd = player.reincarnationamount
23532352
inpute = Number(
2354-
(DOMCacheGetOrSet('reincarnationamount') as HTMLInputElement).value
2353+
getElementById<HTMLInputElement>('reincarnationamount').value
23552354
)
23562355
if (inpute !== inputd || isNaN(inpute + inputd)) {
23572356
getElementById<HTMLInputElement>('reincarnationamount').value = `${
@@ -2361,7 +2360,7 @@ const loadSynergy = async () => {
23612360
}
23622361
inputd = player.autoAscendThreshold
23632362
inpute = Number(
2364-
(DOMCacheGetOrSet('ascensionAmount') as HTMLInputElement).value
2363+
getElementById<HTMLInputElement>('ascensionAmount').value
23652364
)
23662365
if (inpute !== inputd || isNaN(inpute + inputd)) {
23672366
getElementById<HTMLInputElement>('ascensionAmount').value = `${
@@ -2371,20 +2370,17 @@ const loadSynergy = async () => {
23712370
}
23722371
inputd = player.autoAntSacTimer
23732372
inpute = Number(
2374-
(DOMCacheGetOrSet('autoAntSacrificeAmount') as HTMLInputElement).value
2373+
getElementById<HTMLInputElement>('autoAntSacrificeAmount').value
23752374
)
23762375
if (inpute !== inputd || isNaN(inpute + inputd)) {
23772376
getElementById<HTMLInputElement>('autoAntSacrificeAmount').value = `${
23782377
player.autoAntSacTimer || blankSave.autoAntSacTimer
2379-
}`.replace(
2380-
omit,
2381-
'e'
2382-
)
2378+
}`.replace(omit, 'e')
23832379
updateAutoReset(5)
23842380
}
23852381
inputd = player.tesseractAutoBuyerAmount
23862382
inpute = Number(
2387-
(DOMCacheGetOrSet('tesseractAmount') as HTMLInputElement).value
2383+
getElementById<HTMLInputElement>('tesseractAmount').value
23882384
)
23892385
if (inpute !== inputd || isNaN(inpute + inputd)) {
23902386
getElementById<HTMLInputElement>('tesseractAmount').value = `${
@@ -2393,51 +2389,38 @@ const loadSynergy = async () => {
23932389
updateTesseractAutoBuyAmount()
23942390
}
23952391
inputd = player.openCubes
2396-
inpute = Number(
2397-
(DOMCacheGetOrSet('cubeOpensInput') as HTMLInputElement).value
2398-
)
2392+
inpute = Number(getElementById<HTMLInputElement>('cubeOpensInput').value)
23992393
if (inpute !== inputd || isNaN(inpute + inputd)) {
24002394
getElementById<HTMLInputElement>('cubeOpensInput').value = `${player.openCubes || blankSave.openCubes}`
24012395
.replace(omit, 'e')
24022396
updateAutoCubesOpens(1)
24032397
}
24042398
inputd = player.openTesseracts
2405-
inpute = Number(
2406-
(DOMCacheGetOrSet('tesseractsOpensInput') as HTMLInputElement).value
2407-
)
2399+
inpute = Number(getElementById<HTMLInputElement>('tesseractsOpensInput').value)
24082400
if (inpute !== inputd || isNaN(inpute + inputd)) {
24092401
getElementById<HTMLInputElement>('tesseractsOpensInput').value = `${
24102402
player.openTesseracts || blankSave.openTesseracts
24112403
}`.replace(omit, 'e')
24122404
updateAutoCubesOpens(2)
24132405
}
24142406
inputd = player.openHypercubes
2415-
inpute = Number(
2416-
(DOMCacheGetOrSet('hypercubesOpensInput') as HTMLInputElement).value
2417-
)
2407+
inpute = Number(getElementById<HTMLInputElement>('hypercubesOpensInput').value)
24182408
if (inpute !== inputd || isNaN(inpute + inputd)) {
24192409
getElementById<HTMLInputElement>('hypercubesOpensInput').value = `${
24202410
player.openHypercubes || blankSave.openHypercubes
24212411
}`.replace(omit, 'e')
24222412
updateAutoCubesOpens(3)
24232413
}
24242414
inputd = player.openPlatonicsCubes
2425-
inpute = Number(
2426-
(DOMCacheGetOrSet('platonicCubeOpensInput') as HTMLInputElement).value
2427-
)
2415+
inpute = Number(getElementById<HTMLInputElement>('platonicCubeOpensInput').value)
24282416
if (inpute !== inputd || isNaN(inpute + inputd)) {
24292417
getElementById<HTMLInputElement>('platonicCubeOpensInput').value = `${
24302418
player.openPlatonicsCubes || blankSave.openPlatonicsCubes
2431-
}`.replace(
2432-
omit,
2433-
'e'
2434-
)
2419+
}`.replace(omit, 'e')
24352420
updateAutoCubesOpens(4)
24362421
}
24372422
inputd = player.runeBlessingBuyAmount
2438-
inpute = Number(
2439-
(DOMCacheGetOrSet('buyRuneBlessingInput') as HTMLInputElement).value
2440-
)
2423+
inpute = Number(getElementById<HTMLInputElement>('buyRuneBlessingInput').value)
24412424
if (inpute !== inputd || isNaN(inpute + inputd)) {
24422425
getElementById<HTMLInputElement>('buyRuneBlessingInput').value = `${
24432426
player.runeBlessingBuyAmount || blankSave.runeBlessingBuyAmount
@@ -2454,7 +2437,7 @@ const loadSynergy = async () => {
24542437

24552438
inputd = player.runeSpiritBuyAmount
24562439
inpute = Number(
2457-
(DOMCacheGetOrSet('buyRuneSpiritInput') as HTMLInputElement).value
2440+
getElementById<HTMLInputElement>('buyRuneSpiritInput').value
24582441
)
24592442
if (inpute !== inputd || isNaN(inpute + inputd)) {
24602443
getElementById<HTMLInputElement>('buyRuneSpiritInput').value = `${
@@ -2928,7 +2911,7 @@ const padEvery = (str: string, places = 3) => {
29282911
newStr += dec + strParts[1]
29292912
} // see https://www.npmjs.com/package/flatstr
29302913

2931-
;(newStr as unknown as number) | 0
2914+
<number> <unknown> newStr | 0
29322915
return newStr
29332916
}
29342917

@@ -6302,7 +6285,7 @@ export const reloadShit = async (reset = false) => {
63026285
}
63036286
}
63046287

6305-
const saveType = DOMCacheGetOrSet('saveType') as HTMLInputElement
6288+
const saveType = getElementById<HTMLInputElement>('saveType')
63066289
saveType.checked = localStorage.getItem('copyToClipboard') !== null
63076290
}
63086291

src/Toggles.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,15 +723,15 @@ export const toggleCubeSubTab = (indexStr: string) => {
723723
export const updateAutoChallenge = (i: number) => {
724724
switch (i) {
725725
case 1: {
726-
const t = Number.parseFloat((DOMCacheGetOrSet('startAutoChallengeTimerInput') as HTMLInputElement).value) || 0
726+
const t = Number.parseFloat(getElementById<HTMLInputElement>('startAutoChallengeTimerInput').value) || 0
727727
player.autoChallengeTimer.start = Math.max(t, 0)
728728
DOMCacheGetOrSet('startTimerValue').innerHTML = i18next.t('challenges.timeStartSweep', {
729729
time: format(player.autoChallengeTimer.start, 2, true)
730730
})
731731
return
732732
}
733733
case 2: {
734-
const u = Number.parseFloat((DOMCacheGetOrSet('exitAutoChallengeTimerInput') as HTMLInputElement).value) || 0
734+
const u = Number.parseFloat(getElementById<HTMLInputElement>('exitAutoChallengeTimerInput').value) || 0
735735
player.autoChallengeTimer.exit = Math.max(u, 0)
736736

737737
DOMCacheGetOrSet('exitTimerValue').innerHTML = i18next.t('challenges.timeExitChallenge', {
@@ -741,7 +741,7 @@ export const updateAutoChallenge = (i: number) => {
741741
return
742742
}
743743
case 3: {
744-
const v = Number.parseFloat((DOMCacheGetOrSet('enterAutoChallengeTimerInput') as HTMLInputElement).value) || 0
744+
const v = Number.parseFloat(getElementById<HTMLInputElement>('enterAutoChallengeTimerInput').value) || 0
745745
player.autoChallengeTimer.enter = Math.max(v, 0)
746746

747747
DOMCacheGetOrSet('enterTimerValue').innerHTML = i18next.t('challenges.timeEnterChallenge', {
@@ -888,15 +888,15 @@ export const toggleautoopensCubes = (i: number) => {
888888
export const updateRuneBlessingBuyAmount = (i: number) => {
889889
switch (i) {
890890
case 1: {
891-
const t = Math.floor(Number.parseFloat((DOMCacheGetOrSet('buyRuneBlessingInput') as HTMLInputElement).value)) || 1
891+
const t = Math.floor(Number.parseFloat(getElementById<HTMLInputElement>('buyRuneBlessingInput').value)) || 1
892892
player.runeBlessingBuyAmount = Math.max(t, 1)
893893
DOMCacheGetOrSet('buyRuneBlessingToggle').innerHTML = i18next.t('runes.blessings.buyUpTo', {
894894
amount: format(player.runeBlessingBuyAmount)
895895
})
896896
return
897897
}
898898
case 2: {
899-
const u = Math.floor(Number.parseFloat((DOMCacheGetOrSet('buyRuneSpiritInput') as HTMLInputElement).value)) || 1
899+
const u = Math.floor(Number.parseFloat(getElementById<HTMLInputElement>('buyRuneSpiritInput').value)) || 1
900900
player.runeSpiritBuyAmount = Math.max(u, 1)
901901
DOMCacheGetOrSet('buyRuneSpiritToggleValue').innerHTML = i18next.t('runes.spirits.buyUpTo', {
902902
amount: format(player.runeSpiritBuyAmount)

0 commit comments

Comments
 (0)