-
Notifications
You must be signed in to change notification settings - Fork 21
/
gcpd730.js
713 lines (674 loc) · 24.5 KB
/
gcpd730.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
let continue_token = null;
let sessionid = null;
let profileURI = null;
let tabURIparam = 'matchhistorycompetitive';
const maxRetries = 3;
let loadingWholeHistoryCounter = 0;
let loadingWholeHistory = false;
let providedCustomAPIKey = false;
let apikey = '';
let showCommunityBans = true;
chrome.storage.sync.get(['showcommunitybans'], data => {
if (typeof data['showcommunitybans'] == 'undefined') {
chrome.storage.sync.set({
showcommunitybans: true
});
} else {
showCommunityBans = data['showcommunitybans'];
}
});
const banStats = {
vacBans: 0,
gameBans: 0,
communityBans: 0,
recentBans: 0
};
const funStats = {
numberOfMatches: 0,
totalKills: 0,
totalAssists: 0,
totalDeaths: 0,
totalWins: 0,
totalWaitTime: 0,
totalTime: 0
};
let waitTimeRowIndex = 3;
let timeRowIndex = 4;
const getSteamID64 = minProfile =>
'76' + (parseInt(minProfile) + 561197960265728);
const parseTime = time => {
let timeSecs = 0;
if (time.includes(':')) {
const i = time.indexOf(':');
timeSecs += parseInt(time.substr(0, i)) * 60;
timeSecs += parseInt(time.substr(i + 1));
} else {
timeSecs += parseInt(time);
}
return timeSecs;
};
const timeString = time => {
let secs = time;
const days = Math.floor(secs / (24 * 60 * 60));
secs %= 86400;
const hours = Math.floor(secs / (60 * 60))
.toString()
.padStart(2, '0');
secs %= 3600;
const mins = Math.floor(secs / 60)
.toString()
.padStart(2, '0');
secs %= 60;
secs = secs.toString().padStart(2, '0');
let result = `${hours}:${mins}:${secs}`;
if (days) result = `${days.toString()}d ${result}`;
return result;
};
const statusBar = document.createElement('div');
statusBar.style.margin = '8px 0';
statusBar.style.whiteSpace = 'pre-wrap';
const updateStatus = (text, accumulate) => {
if (accumulate) {
statusBar.textContent = statusBar.textContent + '\n' + text;
} else {
statusBar.textContent = text;
}
};
const initVariables = () => {
const profileAnchor = document.querySelector('#global_actions .user_avatar');
if (!profileAnchor) {
updateStatus('Error: .user_avatar element was not found');
}
profileURI = profileAnchor.href;
if (!document.querySelector('#load_more_button')) {
updateStatus(
'No "LOAD MORE HISTORY" button is present, seems like there are no more matches'
);
} else {
const steamContinueScript = document.querySelector(
'#personaldata_elements_container+script'
);
const matchContinueToken = steamContinueScript?.text.match(
/g_sGcContinueToken = '(\d+)'/
);
let matchSessionID = false;
if (!matchContinueToken) {
updateStatus('Error: g_sGcContinueToken was not found');
} else {
continue_token = matchContinueToken[1];
const scriptTags = document.querySelectorAll('script');
for (const scriptTag of scriptTags) {
let g_sessionID = scriptTag.text.match(/g_sessionID = "(.+)"/);
if (g_sessionID != null) {
matchSessionID = g_sessionID;
break;
}
}
}
if (!matchSessionID) {
updateStatus('Error: g_sessionID was not found');
} else {
sessionid = matchSessionID[1];
}
}
const tabOnEl = document.querySelector('.tabOn');
if (tabOnEl) {
tabURIparam = tabOnEl.parentNode.id.split('_').pop();
}
if (
tabURIparam === 'matchhistoryscrimmage' ||
tabURIparam === 'matchhistorycompetitivepermap'
) {
waitTimeRowIndex = 2;
timeRowIndex = 3;
}
if (typeof content !== 'undefined') fetch = content.fetch; // fix for Firefox with disabled third-party cookies
};
const funStatsBar = document.createElement('div');
funStatsBar.style.whiteSpace = 'pre-wrap';
funStatsBar.style.backgroundColor = 'rgba(17, 25, 35, .9)';
funStatsBar.style.borderRadius = '5px';
funStatsBar.style.border = '1px solid #000';
funStatsBar.style.padding = '14px';
funStatsBar.style.position = 'fixed';
funStatsBar.style.left = '0';
funStatsBar.style.bottom = '0';
funStatsBar.style.margin = '4px';
funStatsBar.style.zIndex = '9';
const updateStats = () => {
if (tabURIparam === 'playerreports' || tabURIparam === 'playercommends')
return;
const profileURItrimmed = profileURI.replace(/\/$/, '');
const myAnchors = document.querySelectorAll(
'.inner_name .playerAvatar ' +
`a[href="${profileURItrimmed}"]:not(.banchecker-counted)`
);
myAnchors.forEach(anchorEl => {
myMatchStats = anchorEl.closest('tr').querySelectorAll('td');
funStats.totalKills += parseInt(myMatchStats[2].textContent, 10);
funStats.totalAssists += parseInt(myMatchStats[3].textContent, 10);
funStats.totalDeaths += parseInt(myMatchStats[4].textContent, 10);
anchorEl.classList.add('banchecker-counted');
});
const matchesData = document.querySelectorAll(
'.val_left:not(.banchecker-counted)'
);
funStats.numberOfMatches += matchesData.length;
matchesData.forEach(matchData => {
matchData.querySelectorAll('td').forEach((dataEl, index) => {
if (index < 2) return;
const data = dataEl.innerText.trim();
if (data.includes(':')) {
const i = data.indexOf(':');
const value = data.substr(i + 1);
if (index === waitTimeRowIndex) {
funStats.totalWaitTime += parseTime(value);
} else if (index === timeRowIndex) {
funStats.totalTime += parseTime(value);
}
}
});
matchData.classList.add('banchecker-counted');
});
let matchesWon = 0;
let matchesLost = 0;
let matchesTied = 0;
document
.querySelectorAll(
`.inner_name .playerAvatar a[href="${profileURItrimmed}"]`
)
.forEach(anchorEl => {
const row = anchorEl.closest('tr');
if (row.classList.contains('banchecker-matchresult-tie')) matchesTied++;
if (row.classList.contains('banchecker-matchresult-win')) matchesWon++;
if (row.classList.contains('banchecker-matchresult-lose')) matchesLost++;
});
funStatsBar.textContent =
'Some fun stats for loaded matches\n\n' +
`Number of matches: ${funStats.numberOfMatches}\n` +
`Won: ${matchesWon} | Lost: ${matchesLost} | Tied: ${matchesTied}\n\n` +
`Kills: ${funStats.totalKills} | Deaths: ${funStats.totalDeaths} | Assists: ${funStats.totalAssists}\n\n` +
`K/D: ${(funStats.totalKills / funStats.totalDeaths).toFixed(3)} | ` +
`(K+A)/D: ${(
(funStats.totalKills + funStats.totalAssists) /
funStats.totalDeaths
).toFixed(3)}\n\n` +
`Total wait time: ${timeString(funStats.totalWaitTime)}\n` +
`Total match time: ${timeString(funStats.totalTime)}`;
};
const formatMatchTables = () => {
const daysSince = dateString => {
const matchDate = dateString.match(
/(20\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/
);
let daysSinceMatch = -1;
if (matchDate.length > 6) {
const year = parseInt(matchDate[1], 10);
const month = parseInt(matchDate[2], 10) - 1;
const day = parseInt(matchDate[3], 10);
const hour = parseInt(matchDate[4], 10);
const minute = parseInt(matchDate[5], 10);
const second = parseInt(matchDate[6], 10);
const matchDateObj = new Date(year, month, day, hour, minute, second);
const matchDayTime = matchDateObj.getTime();
const currentTime = Date.now();
const timePassed = currentTime - matchDayTime;
daysSinceMatch = Math.ceil(timePassed / (1000 * 60 * 60 * 24));
}
return daysSinceMatch;
};
if (tabURIparam === 'playerreports' || tabURIparam === 'playercommends') {
document
.querySelectorAll(
'.generic_kv_table > tbody > tr:not(:first-child):not(.banchecker-profile)'
)
.forEach(report => {
const dateEl = report.querySelector('td:first-child');
const daysSinceMatch = daysSince(dateEl.textContent);
const minProfile =
report.querySelector('.linkTitle').dataset.miniprofile;
report.dataset.steamid64 = getSteamID64(minProfile);
report.dataset.dayssince = daysSinceMatch;
report.classList.add('banchecker-profile');
report.classList.add('banchecker-formatted');
});
} else {
document
.querySelectorAll(
'.csgo_scoreboard_inner_right:not(.banchecker-formatted)'
)
.forEach(table => {
const leftColumn = table.parentElement.parentElement.querySelector(
'.csgo_scoreboard_inner_left'
);
const daysSinceMatch = daysSince(leftColumn.textContent);
table.querySelectorAll('tbody > tr').forEach((tr, i) => {
if (i === 0 || tr.childElementCount < 3) return;
const minProfile = tr.querySelector('.linkTitle').dataset.miniprofile;
const steamID64 = getSteamID64(minProfile);
tr.dataset.steamid64 = steamID64;
tr.dataset.dayssince = daysSinceMatch;
tr.classList.add('banchecker-profile');
});
const scoreboard = table.querySelector('.csgo_scoreboard_score');
if (scoreboard) {
const scores = scoreboard.textContent
.split(' : ')
.map(s => Number(s));
if (scores[0] === scores[1]) {
table.querySelectorAll('tbody > tr').forEach((tr, i) => {
if (i === 0 || tr.childElementCount < 3) return;
tr.classList.add('banchecker-matchresult-tie');
});
} else {
let matchresult = scores[0] > scores[1] ? 'win' : 'lose';
table.querySelectorAll('tbody > tr').forEach((tr, i) => {
if (tr.querySelector('.csgo_scoreboard_score')) {
// flip result for rows after scoreboard
matchresult = scores[0] > scores[1] ? 'lose' : 'win';
}
if (i === 0 || tr.childElementCount < 3) return;
tr.classList.add(`banchecker-matchresult-${matchresult}`);
});
}
}
table.classList.add('banchecker-formatted');
const parentRow = table.closest('tr');
if (parentRow.style.display === '')
parentRow.style.display = 'table-row';
});
}
};
const fetchMatchHistory = () => {
updateStatus('Loading Match history...');
loadingWholeHistory = true;
const continueTextEl = document.querySelector(
'#load_more_button_continue_text'
);
const callback = (mutationList, observer) => {
for (const mutation of mutationList) {
if (
mutation.attributeName === 'style' &&
continueTextEl.style.display === 'none'
) {
updateStatus('Looks like we fetched all available matches!', true);
}
}
};
const continueTextObserver = new MutationObserver(callback);
continueTextObserver.observe(continueTextEl, { attributes: true });
if (loadMoreButton.style.display === 'none') {
updateStatus('No more matches to load!', true);
} else {
document.querySelector('#load_more_button').click();
}
};
const checkBans = players => {
const uniquePlayers = [...new Set(players)];
let batches = uniquePlayers.reduce((arr, player, i) => {
const batchIndex = Math.floor(i / 100);
if (!arr[batchIndex]) {
arr[batchIndex] = [player];
} else {
arr[batchIndex].push(player);
}
return arr;
}, []);
const fetchBatch = (i, retryCount) => {
updateStatus(
`Loaded unchecked matches contain ${uniquePlayers.length} players.\n` +
`We can scan 100 players at a time so we're sending ${batches.length} ` +
`request${batches.length > 1 ? 's' : ''}.\n` +
`${i} successful request${i === 1 ? '' : 's'} so far...`
);
chrome.runtime.sendMessage(
chrome.runtime.id,
{
action: 'fetchBans',
apikey: apikey,
batch: batches[i]
},
({ json, error }) => {
if (error !== undefined) {
if (error === 'No permissions to access Steam Web API') {
updateStatus(error);
const openOptionsBtn = document.createElement('button');
openOptionsBtn.textContent = 'Open options to grant permissions';
openOptionsBtn.onclick = () =>
chrome.runtime.sendMessage(chrome.runtime.id, {
action: 'showOptions'
});
document.querySelector('#banchecker-menu').append(openOptionsBtn);
} else {
updateStatus(
`Error while scanning players for bans:\n${error}` +
`${
retryCount !== undefined && retryCount > 0
? `\n\nRetrying to scan... ${maxRetries - retryCount}/3`
: `\n\nCouldn't scan for bans after ${maxRetries} retries :(`
}`
);
if (retryCount > 0) {
setTimeout(() => fetchBatch(i, retryCount - 1), 3000);
}
}
return;
}
json.players.forEach(player => {
const playerEls = document.querySelectorAll(
`tr[data-steamid64="${player.SteamId}"]`
);
const daySinceLastMatch = parseInt(
playerEls[0].dataset.dayssince,
10
);
let verdict = '';
if (player.NumberOfVACBans > 0) {
verdict += 'VAC';
banStats.vacBans++;
}
if (player.NumberOfGameBans > 0) {
if (verdict) verdict += ' &\n';
verdict += 'Game';
banStats.gameBans++;
}
if (showCommunityBans && player.CommunityBanned) {
if (verdict) verdict += ' &\n';
verdict += 'Community';
banStats.communityBans++;
}
if (verdict) {
const daysAfter = daySinceLastMatch - player.DaysSinceLastBan;
if (daySinceLastMatch > player.DaysSinceLastBan) {
banStats.recentBans++;
verdict += '+' + daysAfter;
} else {
verdict += daysAfter;
}
}
playerEls.forEach(playerEl => {
playerEl.classList.add('banchecker-checked');
const verdictEl = playerEl.querySelector('.banchecker-bans');
if (verdict) {
if (daySinceLastMatch > player.DaysSinceLastBan) {
verdictEl.style.color = 'red';
playerEl
.closest("tr[style*='display: table-row;']")
.classList.add('banchecker-matchwithban');
} else {
verdictEl.style.color = 'grey';
}
verdictEl.style.cursor = 'help';
verdictEl.textContent = verdict;
verdictEl.title = `Days since last ban: ${player.DaysSinceLastBan}`;
} else {
verdictEl.textContent = '';
}
});
});
if (batches.length > i + 1 && providedCustomAPIKey) {
setTimeout(() => fetchBatch(i + 1), 1000);
} else if (batches.length > i + 1 && !providedCustomAPIKey) {
updateStatus(
`Looks like we're done.\n\n` +
`Loaded unchecked matches contain ${uniquePlayers.length} players.\n` +
'You did not provide your own Steam API key, only 100 players were scanned!'
);
} else {
updateStatus(
`Looks like we're done.\n\n` +
`There ` +
(banStats.recentBans === 1
? `was 1 player`
: `were ${banStats.recentBans} players`) +
` who got banned after playing with you!\n\n` +
`Total ban stats: ${banStats.vacBans} VAC and ${banStats.gameBans} ` +
`Game banned players in games we scanned (a lot of these could happen outside of Counter-Strike.)\n` +
(showCommunityBans
? `Community bans: ${banStats.communityBans} (these can be hidden in settings)\n`
: '') +
`Total amount of unique players encountered: ${uniquePlayers.length}` +
`\n\nHover over ban status to check how many days have passed since last ban.`
);
if (banStats.recentBans > 0) {
document.querySelector('#banchecker-hideMatchesChk').style.display =
'block';
}
}
}
);
};
fetchBatch(0, maxRetries);
};
const checkLoadedMatchesForBans = () => {
if (tabURIparam === 'playerreports' || tabURIparam === 'playercommends') {
const tableHeader = document.querySelector(
'.generic_kv_table > tbody > tr:first-child'
);
if (!tableHeader.classList.contains('banchecker-withcolumn')) {
tableHeader.classList.add('banchecker-withcolumn');
const bansHeader = document.createElement('th');
bansHeader.textContent = 'Ban';
tableHeader.appendChild(bansHeader);
}
const uncheckedPlayers = document.querySelectorAll(
'.generic_kv_table > tbody > tr:not(.banchecker-withcolumn)'
);
uncheckedPlayers.forEach(tr => {
tr.classList.add('banchecker-withcolumn');
const bansPlaceholder = document.createElement('td');
bansPlaceholder.classList.add('banchecker-bans');
bansPlaceholder.textContent = '?';
tr.appendChild(bansPlaceholder);
});
} else {
const tables = document.querySelectorAll(
'.banchecker-formatted:not(.banchecker-withcolumn)'
);
tables.forEach(table => {
table.classList.add('banchecker-withcolumn');
table.querySelectorAll('tr').forEach((tr, i) => {
if (i === 0) {
const bansHeader = document.createElement('th');
bansHeader.textContent = 'Bans';
bansHeader.style.minWidth = '5.6em';
tr.appendChild(bansHeader);
} else if (tr.childElementCount > 3) {
const bansPlaceholder = document.createElement('td');
bansPlaceholder.classList.add('banchecker-bans');
bansPlaceholder.textContent = '?';
tr.appendChild(bansPlaceholder);
} else {
const scoreboard = tr.querySelector('td');
if (scoreboard) scoreboard.setAttribute('colspan', '9');
}
});
});
}
const playersEl = document.querySelectorAll(
'.banchecker-profile:not(.banchecker-checked):not(.banchecker-checking)'
);
let playersArr = [];
playersEl.forEach(player => {
player.classList.add('banchecker-checking');
playersArr.push(player.dataset.steamid64);
});
checkBans(playersArr);
};
const menu = document.createElement('div');
menu.style.padding = '0 14px';
menu.id = 'banchecker-menu';
const createSteamButton = (text, iconURI) => {
const button = document.createElement('div');
// pullup_item class style replication using js
// TODO: move to separate css file for sanity
button.style.display = 'inline-block';
button.style.backgroundColor = 'rgba( 103, 193, 245, 0.2 )';
button.style.padding = '3px 8px 0px 0px';
button.style.borderRadius = '2px';
button.style.marginRight = '6px';
button.style.cursor = 'pointer';
button.style.lineHeight = '18px';
button.style.color = '#66c0f4';
button.style.fontSize = '11px';
button.onmouseover = () => {
button.style.backgroundColor = 'rgba( 102, 192, 244, 0.4 )';
button.style.color = '#ffffff';
};
button.onmouseout = () => {
button.style.backgroundColor = 'rgba( 103, 193, 245, 0.2 )';
button.style.color = '#66c0f4';
};
const iconEl = document.createElement('div');
iconEl.className = 'menu_ico';
iconEl.style.display = 'inline-block';
iconEl.style.verticalAlign = 'top';
iconEl.style.padding = iconURI ? '1px 7px 0 6px' : '1px 8px 0 0';
iconEl.style.minHeight = '22px';
if (iconURI) {
const image = document.createElement('img');
image.src = iconURI;
image.width = '16';
image.height = '16';
image.border = '0';
iconEl.appendChild(image);
}
button.appendChild(iconEl);
const textNode = document.createTextNode(text);
button.appendChild(textNode);
return button;
};
const fetchButton = createSteamButton('Load whole match history');
fetchButton.onclick = () => {
fetchMatchHistory();
fetchButton.onclick = () => {
updateStatus(
'This button was already pressed. Reload the page if you want to start over.'
);
};
};
menu.appendChild(fetchButton);
const checkBansButton = createSteamButton('Check loaded matches for bans');
checkBansButton.onclick = () => {
checkLoadedMatchesForBans();
if (!providedCustomAPIKey) checkBansButton.onclick = null;
};
const getStoredAPIKey = async () => {
const data = await chrome.storage.sync.get(['customapikey']);
if (typeof data.customapikey === 'undefined') {
const defaultkeys = [
'5DA40A4A4699DEE30C1C9A7BCE84C914',
'5970533AA2A0651E9105E706D0F8EDDC',
'2B3382EBA9E8C1B58054BD5C5EE1C36A'
];
apikey = defaultkeys[Math.floor(Math.random() * 3)];
statusBar.textContent =
'Only 100 players from the most recent matches will be scanned without providing your own API key!';
} else {
providedCustomAPIKey = true;
apikey = data.customapikey;
}
fetchButton.insertAdjacentElement('afterend', checkBansButton);
};
getStoredAPIKey();
menu.appendChild(statusBar);
const hideMatchesWithNoBans = document.createElement('label');
hideMatchesWithNoBans.id = 'banchecker-hideMatchesChk';
hideMatchesWithNoBans.style.display = 'none';
const hideMatchesWithNoBansChk = document.createElement('input');
hideMatchesWithNoBansChk.type = 'checkbox';
hideMatchesWithNoBansChk.style.marginLeft = 0;
hideMatchesWithNoBans.append(hideMatchesWithNoBansChk);
hideMatchesWithNoBans.append('Hide matches with no bans');
hideMatchesWithNoBansChk.addEventListener('change', event => {
const hide = event.currentTarget.checked;
const matchesWithNoBans = document.querySelectorAll(
'.csgo_scoreboard_root tr[style*="display: table-row;"]:not(.banchecker-matchwithban),' +
'.csgo_scoreboard_root tr.banchecker-matchwithoutban'
);
matchesWithNoBans.forEach(el => {
el.classList.add('banchecker-matchwithoutban');
el.style.display = hide ? 'none' : 'table-row';
});
});
menu.appendChild(hideMatchesWithNoBans);
menu.appendChild(funStatsBar);
document.querySelector('#subtabs').insertAdjacentElement('afterend', menu);
initVariables();
formatMatchTables();
updateStats();
const loadMoreButton = document.querySelector(
'.load_more_history_area #load_more_clickable'
);
const loadingElement = document.querySelector('#inventory_history_loading');
if (loadMoreButton && loadingElement) {
const continueTextElement = document.querySelector(
'#load_more_button_continue_text'
);
const callback = (mutationList, observer) => {
for (const mutation of mutationList) {
if (
mutation.attributeName === 'style' &&
loadingElement.style.display === 'none'
) {
formatMatchTables();
updateStats();
if (loadingWholeHistory) {
if (continueTextElement.style.display === 'none') return;
loadingWholeHistoryCounter++;
updateStatus(
`Loading Match history... Pages loaded: ${loadingWholeHistoryCounter}`
);
loadMoreButton.click();
}
}
}
};
const observer = new MutationObserver(callback);
observer.observe(loadingElement, { attributes: true });
}
// embed settings
let settingsInjected = false;
const showSettings = () => {
if (settingsInjected) {
const settingsShade = document.getElementById('settingsShade');
const settingsDiv = document.getElementById('settingsDiv');
settingsShade.className = 'fadeIn';
settingsDiv.className = 'fadeIn';
} else {
settingsInjected = true;
fetch(chrome.runtime.getURL('/options.html'))
.then(resp => resp.text())
.then(settingsHTML => {
const settingsDiv = document.createElement('div');
settingsDiv.id = 'settingsDiv';
settingsDiv.innerHTML = settingsHTML;
document.body.appendChild(settingsDiv);
const settingsShade = document.createElement('div');
settingsShade.id = 'settingsShade';
settingsShade.addEventListener('click', hideSettings);
document.body.appendChild(settingsShade);
initOptions();
showSettings();
});
}
};
const hideSettings = () => {
const settingsShade = document.getElementById('settingsShade');
const settingsDiv = document.getElementById('settingsDiv');
settingsShade.className = 'fadeOut';
settingsDiv.className = 'fadeOut';
chrome.storage.sync.get(['customapikey', 'showcommunitybans'], data => {
if (typeof data.customapikey !== 'undefined' && !providedCustomAPIKey) {
location.reload();
} else {
updateStatus('Reload the page if you changed your API key!', true);
}
if (typeof data.showcommunitybans !== undefined) {
showCommunityBans = data.showcommunitybans;
}
});
};
const bancheckerSettingsButton = createSteamButton('Set Steam API key');
bancheckerSettingsButton.onclick = () => showSettings();
statusBar.insertAdjacentElement('beforeBegin', bancheckerSettingsButton);