-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
94 lines (94 loc) · 3.17 KB
/
background.js
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
let seedResults = {};
let allMultipliers = {};
let betsSinceMultiplier = {};
let lastOccurrenceMultiplier = {};
let lastPlayedGame = 'Plinko';
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'PLINKO_BET_DATA') {
handlePlinkoBet(message.data);
} else if (message.type === 'KENO_BET_DATA') {
handleKenoBet(message.data);
} else if (message.type === 'RESET_STATS') {
resetStats();
sendResponse({ success: true });
return true;
}
});
function handlePlinkoBet(betData) {
const seed = betData.seed || 'unknown';
if (!seedResults[seed]) {
seedResults[seed] = [];
allMultipliers[seed] = {};
betsSinceMultiplier[seed] = {};
lastOccurrenceMultiplier[seed] = {};
}
seedResults[seed].unshift(betData);
updateAllMultipliers(seed, betData.payoutMultiplier);
lastPlayedGame = 'Plinko';
saveToStorage();
}
function handleKenoBet(betData) {
const seed = betData.seed || 'unknown';
if (!kenoResults[seed]) {
kenoResults[seed] = [];
}
kenoResults[seed].unshift(betData);
lastPlayedGame = 'Keno';
saveToStorage();
}
function updateAllMultipliers(seed, multiplier) {
allMultipliers[seed][multiplier] = (allMultipliers[seed][multiplier] || 0) + 1;
// Update lastOccurrenceMultiplier before resetting betsSinceMultiplier
if (betsSinceMultiplier[seed][multiplier] !== undefined) {
lastOccurrenceMultiplier[seed][multiplier] = betsSinceMultiplier[seed][multiplier];
}
// Reset betsSinceMultiplier for the current multiplier
betsSinceMultiplier[seed][multiplier] = 0;
// Increment betsSinceMultiplier for all other multipliers
Object.keys(betsSinceMultiplier[seed]).forEach(m => {
if (m !== multiplier.toString()) {
betsSinceMultiplier[seed][m]++;
}
});
}
function saveToStorage() {
chrome.storage.local.set({
seedResults: seedResults,
allMultipliers: allMultipliers,
betsSinceMultiplier: betsSinceMultiplier,
lastOccurrenceMultiplier: lastOccurrenceMultiplier,
kenoResults: kenoResults,
lastPlayedGame: lastPlayedGame
}, () => {
console.log('Data saved to storage');
});
}
function resetStats() {
console.log('Resetting all stats');
seedResults = {};
allMultipliers = {};
betsSinceMultiplier = {};
lastOccurrenceMultiplier = {};
kenoResults = {};
lastPlayedGame = 'Plinko';
chrome.storage.local.set({
seedResults: seedResults,
allMultipliers: allMultipliers,
betsSinceMultiplier: betsSinceMultiplier,
lastOccurrenceMultiplier: lastOccurrenceMultiplier,
kenoResults: kenoResults,
lastPlayedGame: lastPlayedGame
}, () => {
console.log('Stats reset and saved to storage');
});
}
// Initialize data from storage
chrome.storage.local.get(['seedResults', 'allMultipliers', 'betsSinceMultiplier', 'lastOccurrenceMultiplier', 'kenoResults'], (result) => {
seedResults = result.seedResults || {};
allMultipliers = result.allMultipliers || {};
betsSinceMultiplier = result.betsSinceMultiplier || {};
lastOccurrenceMultiplier = result.lastOccurrenceMultiplier || {};
kenoResults = result.kenoResults || {};
console.log('Data initialized from storage');
});
console.log('Stake Bet Analyzer: Service worker setup complete');