Skip to content

Commit 50646bf

Browse files
committed
fixup! always use synergism.cc for quark bonus
1 parent c2601f3 commit 50646bf

File tree

1 file changed

+0
-84
lines changed

1 file changed

+0
-84
lines changed

src/Quark.ts

-84
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,5 @@
1-
/* Functions which Handle Quark Gains, */
2-
3-
import { DOMCacheGetOrSet } from './Cache/DOM'
41
import { calculateCubeQuarkMultiplier, calculateQuarkMultiplier } from './Calculate'
52
import { format, player } from './Synergism'
6-
import { Alert } from './UpdateHTML'
7-
8-
const getBonus = async (): Promise<null | number> => {
9-
if (!navigator.onLine) {
10-
return null
11-
}
12-
if (document.visibilityState === 'hidden') {
13-
return null
14-
}
15-
16-
try {
17-
const r = await fetch('https://synergism-quarks.khafra.workers.dev/')
18-
const j = await r.json() as { bonus: number }
19-
20-
return j.bonus
21-
} catch (e) {
22-
console.log(`workers.dev: ${(e as Error).message}`)
23-
}
24-
25-
try {
26-
const r = await fetch('https://api.github.com/gists/44be6ad2dcf0d44d6a29dffe1d66a84a', {
27-
headers: {
28-
Accept: 'application/vnd.github.v3+json'
29-
}
30-
})
31-
32-
const t = await r.json() as { files: Record<string, { content: string }> }
33-
const b = Number(t.files['SynergismQuarkBoost.txt'].content)
34-
35-
return b
36-
} catch (e) {
37-
console.log(`GitHub Gist: ${(e as Error).message}`)
38-
}
39-
40-
return null
41-
}
423

434
export const quarkHandler = () => {
445
let maxTime = 90000 // In Seconds
@@ -82,21 +43,12 @@ export class QuarkHandler {
8243
/** Quark amount */
8344
private QUARKS = 0
8445

85-
private interval: ReturnType<typeof setInterval> | null = null
86-
8746
constructor ({ bonus, quarks }: { bonus?: number; quarks: number }) {
8847
this.QUARKS = quarks
8948

9049
if (bonus) {
9150
this.BONUS = bonus
92-
} else {
93-
void this.getBonus()
9451
}
95-
96-
if (this.interval) clearInterval(this.interval)
97-
98-
// although the values are cached for 15 mins, refresh every 5
99-
this.interval = setInterval(this.getBonus.bind(this), 60 * 1000 * 5)
10052
}
10153

10254
/*** Calculates the number of quarks to give with the current bonus. */
@@ -122,42 +74,6 @@ export class QuarkHandler {
12274
return this
12375
}
12476

125-
async getBonus () {
126-
const el = DOMCacheGetOrSet('currentBonus')
127-
128-
if (location.hostname === 'synergism.cc') {
129-
return
130-
}
131-
132-
if (localStorage.getItem('quarkBonus') !== null) { // is in cache
133-
const { bonus, fetched } = JSON.parse(localStorage.getItem('quarkBonus')!) as { bonus: number; fetched: number }
134-
if (Date.now() - fetched < 60 * 1000 * 15) { // cache is younger than 15 minutes
135-
el.textContent = `Generous patrons give you a bonus of ${bonus}% more Quarks!`
136-
return this.BONUS = bonus
137-
}
138-
} else if (!navigator.onLine) {
139-
return el.textContent = 'Current Bonus: N/A% (offline)!'
140-
} else if (document.hidden) {
141-
return el.textContent = 'Current Bonus: N/A% (unfocused)!'
142-
}
143-
144-
const b = await getBonus()
145-
146-
if (b === null) {
147-
return
148-
} else if (Number.isNaN(b) || typeof b !== 'number') {
149-
return Alert('No bonus could be applied, a network error occurred! [Invalid Bonus] :(')
150-
} else if (!Number.isFinite(b)) {
151-
return Alert('No bonus could be applied, an error occurred. [Infinity] :(')
152-
} else if (b < 0) {
153-
return Alert('No bonus could be applied, an error occurred. [Zero] :(')
154-
}
155-
156-
el.textContent = `Generous patrons give you a bonus of ${b}% more Quarks!`
157-
localStorage.setItem('quarkBonus', JSON.stringify({ bonus: b, fetched: Date.now() }))
158-
this.BONUS = b
159-
}
160-
16177
public toString (val: number): string {
16278
return format(Math.floor(this.applyBonus(val)), 0, true)
16379
}

0 commit comments

Comments
 (0)