-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.js
550 lines (515 loc) · 22.2 KB
/
main.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
//Настройки
// noinspection ES6ConvertVarToLetConst
var settings
//Общая статистика
// noinspection ES6ConvertVarToLetConst
var generalStats
//Статистика за сегодня
// noinspection ES6ConvertVarToLetConst
var todayStats
//Оновная база данных
// noinspection ES6ConvertVarToLetConst
var db
//База данных логов
// noinspection ES6ConvertVarToLetConst
var dbLogs
//Текущие открытые вкладки расширением
// noinspection ES6ConvertVarToLetConst
var openedProjects = new Map()
let onLine
self.addEventListener('error', (event) => onUnhandledError(event))
self.addEventListener('unhandledrejection', (event) => onUnhandledError(event))
function onUnhandledError(event) {
let error
if (event.reason) {
error = event.reason
} else if (event.error) {
error = event.error
} else {
error = 'Unidentified error, see the details in the console '
if (console._error) console._error(event)
else console.error(event)
error += JSON.stringify(event)
}
if (self.createNotif) { // noinspection JSIgnoredPromiseFromCall
createNotif(error, 'error', {dontLog: true})
document.querySelectorAll('button[disabled]').forEach((el) => el.disabled = false)
}
if (!dbLogs) return
const time = new Date().toLocaleString().replace(',', '')
if (error.stack) error = error.stack
const log = '[' + time + ' ERROR]: ' + error
try {
dbLogs.put('logs', log).catch(e => {
if (console._error) console._error(e)
else console.error(e)
})
} catch (e) {
if (console._error) console._error(e)
else console.error(e)
}
}
//Инициализация настроек расширения
async function initializeConfig(background, version) {
if (!dbLogs) {
dbLogs = await idb.openDB('logs', 1, {
upgrade(db/*, oldVersion, newVersion, transaction*/) {
db.createObjectStore('logs', {autoIncrement: true})
}
})
}
// noinspection JSUnusedGlobalSymbols
try {
db = await idb.openDB('avr', version ? version : 15, {upgrade})
} catch (error) {
//На случай если это версия MultiVote
if (error.name === 'VersionError') {
if (version) {
dbError({target: {source: {name: 'avr'}, error: error}})
return
}
console.log('Ошибка версии базы данных, возможно вы на версии MultiVote, пытаемся загрузить настройки версии MultiVote')
await initializeConfig(background, 150)
return
}
dbError({target: {source: {name: 'avr'}, error: error}})
return
}
db.onerror = (event) => dbError(event, false)
dbLogs.onerror = (event) => dbError(event, true)
function dbError(event, logs) {
if (background) {
sendNotification(chrome.i18n.getMessage('errordbTitle', event.target.source.name), event.target.error.message, 'error', 'openSettings')
if (logs) {
console._error(chrome.i18n.getMessage('errordb', [event.target.source.name, event.target.error.message]))
} else {
console.error(chrome.i18n.getMessage('errordb', [event.target.source.name, event.target.error.message]))
}
} else {
createNotif(chrome.i18n.getMessage('errordb', [event.target.source.name, event.target.error.message]), 'error')
}
}
settings = await db.get('other', 'settings')
generalStats = await db.get('other', 'generalStats')
todayStats = await db.get('other', 'todayStats')
openedProjects = await db.get('other', 'openedProjects')
onLine = await db.get('other', 'onLine')
if (!background) return
if (state !== 'activated') {
console.log(chrome.i18n.getMessage('start', chrome.runtime.getManifest().version))
if (openedProjects.size > 0) {
for (const [key, value] of openedProjects) {
openedProjects.delete(key)
// noinspection ES6MissingAwait
tryCloseTab(key, value, 0)
}
await db.put('other', openedProjects, 'openedProjects')
}
// noinspection ES6MissingAwait
checkVote()
} else {
if (!openedProjects.size) {
updateListeners(false)
}
}
}
async function upgrade(db, oldVersion, newVersion, transaction) {
if (oldVersion == null) oldVersion = 1
if (oldVersion !== newVersion) {
if (self.createNotif) {
// noinspection ES6MissingAwait
createNotif(chrome.i18n.getMessage('oldSettings', [oldVersion, newVersion]), 'hint')
} else {
console.log(chrome.i18n.getMessage('oldSettings', [oldVersion, newVersion]))
}
}
if (oldVersion === 0) {
const projects = db.createObjectStore('projects', {autoIncrement: true})
projects.createIndex('rating, id, nick', ['rating', 'id', 'nick'])
projects.createIndex('rating, id', ['rating', 'id'])
projects.createIndex('rating', 'rating')
const other = db.createObjectStore('other')
settings = {
disabledNotifStart: true,
disabledNotifInfo: false,
disabledNotifWarn: false,
disabledNotifError: false,
enabledSilentVote: true,
disabledCheckInternet: false,
disabledOneVote: false,
disabledRestartOnTimeout: false,
disabledFocusedTab: false,
enableCustom: false,
timeout: 10000,
timeoutError: 900000,
timeoutVote: 900000,
disabledWarnCaptcha: false,
debug: false,
expertMode: false
}
await other.add(settings, 'settings')
generalStats = {
successVotes: 0,
monthSuccessVotes: 0,
lastMonthSuccessVotes: 0,
errorVotes: 0,
laterVotes: 0,
lastSuccessVote: null,
lastAttemptVote: null,
added: Date.now()
}
todayStats = {
successVotes: 0,
errorVotes: 0,
laterVotes: 0,
lastSuccessVote: null,
lastAttemptVote: null
}
await other.add(generalStats, 'generalStats')
await other.add(todayStats, 'todayStats')
await other.add(openedProjects, 'openedProjects')
onLine = true
other.add(onLine, 'onLine')
return
}
if (!transaction) transaction = db.transaction(['projects', 'other'], 'readwrite')
if (oldVersion <= 1) {
todayStats = {
successVotes: 0,
errorVotes: 0,
laterVotes: 0,
lastSuccessVote: null,
lastAttemptVote: null
}
const store = transaction.objectStore('other')
await store.put(todayStats, 'todayStats')
settings = await store.get('settings')
settings.timeout = 10000
await transaction.objectStore('other').put(settings, 'settings')
}
if (oldVersion <= 3) {
const store = transaction.objectStore('projects')
let cursor = await store.index('rating').openCursor('DiscordBotList')
while (cursor) {
const project = cursor.value
project.game = 'bots'
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
}
cursor = await store.index('rating').openCursor('MinecraftRating')
while (cursor) {
const project = cursor.value
project.game = 'projects'
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
}
cursor = await store.index('rating').openCursor('PixelmonServers')
while (cursor) {
const project = cursor.value
project.game = 'pixelmonservers.com'
project.rating = 'MineServers'
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
}
}
if (oldVersion <= 4) {
const store = transaction.objectStore('projects')
let cursor = await store.index('rating').openCursor('MCServerList')
while (cursor) {
const project = cursor.value
project.maxCountVote = 5
project.countVote = 0
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
}
let cursor2 = await store.index('rating').openCursor('CzechCraft')
while (cursor2) {
const project = cursor2.value
project.maxCountVote = 5
project.countVote = 0
await cursor2.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor2 = await cursor2.continue()
}
let cursor3 = await store.index('rating').openCursor('MinecraftServery')
while (cursor3) {
const project = cursor3.value
project.maxCountVote = 5
project.countVote = 0
await cursor3.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor3 = await cursor3.continue()
}
}
if (oldVersion <= 7) {
settings = await transaction.objectStore('other').get('settings')
settings.timeoutError = 900000
settings.disabledOneVote = false
settings.disabledFocusedTab = false
await transaction.objectStore('other').put(settings, 'settings')
}
if (oldVersion <= 8) {
const store = transaction.objectStore('projects')
let cursor = await store.index('rating').openCursor('WARGM')
while (cursor) {
const project = cursor.value
project.randomize = {min: 0, max: 14400000}
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
}
}
if (oldVersion <= 9) {
openedProjects = new Map()
await transaction.objectStore('other').put(openedProjects, 'openedProjects')
}
if (oldVersion <= 10) {
settings = await transaction.objectStore('other').get('settings')
settings.timeoutVote = 900000
await transaction.objectStore('other').put(settings, 'settings')
}
if (oldVersion <= 11) {
onLine = true
await transaction.objectStore('other').put(onLine, 'onLine')
}
if (oldVersion <= 12) {
const store = transaction.objectStore('projects')
let cursor = await store.index('rating').openCursor('CraftList')
while (cursor) {
const project = cursor.value
project.randomize = {min: 0, max: 3600000}
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
}
}
if (oldVersion <= 13) {
const oldNames = new Map([
['TopCraft', 'topcraft.ru'],
['McTOP', 'mctop.su'],
['MCRate', 'mcrate.su'],
['MinecraftRating', 'minecraftrating.ru'],
['MonitoringMinecraft', 'monitoringminecraft.ru'],
['IonMc', 'ionmc.top'],
['MinecraftServersOrg', 'minecraftservers.org'],
['ServeurPrive', 'serveur-prive.net'],
['PlanetMinecraft', 'planetminecraft.com'],
['TopG', 'topg.org'],
['ListForge', 'listforge.net'],
['MinecraftServerList', 'minecraft-server-list.com'],
['ServerPact', 'serverpact.com'],
['MinecraftIpList', 'minecraftiplist.com'],
['TopMinecraftServers', 'topminecraftservers.org'],
['MinecraftServersBiz', 'minecraftservers.biz'],
['HotMC', 'hotmc.ru'],
['MinecraftServerNet', 'minecraft-server.net'],
['TopGames', 'top-games.net'],
['TMonitoring', 'tmonitoring.com'],
['TopGG', 'top.gg'],
['DiscordBotList', 'discordbotlist.com'],
['Discords', 'discords.com'],
['MMoTopRU', 'mmotop.ru'],
['MCServers', 'mc-servers.com'],
['MinecraftList', 'minecraftlist.org'],
['MinecraftIndex', 'minecraft-index.com'],
['ServerList101', 'serverlist101.com'],
['MCServerList', 'mcserver-list.eu'],
['CraftList', 'craftlist.org'],
['CzechCraft', 'czech-craft.eu'],
['MinecraftBuzz', 'minecraft.buzz'],
['MinecraftServery', 'minecraftservery.eu'],
['RPGParadize', 'rpg-paradize.com'],
['MinecraftServerListNet', 'minecraft-serverlist.net'],
['MinecraftServerEu', 'minecraft-server.eu'],
['MinecraftKrant', 'minecraftkrant.nl'],
['TrackyServer', 'trackyserver.com'],
['MCListsOrg', 'mc-lists.org'],
['TopMCServersCom', 'topmcservers.com'],
['BestServersCom', 'bestservers.com'],
['CraftListNet', 'craft-list.net'],
['MinecraftServersListOrg', 'minecraft-servers-list.org'],
['ServerListe', 'serverliste.net'],
['gTop100', 'gtop100.com'],
['WARGM', 'wargm.ru'],
['MineStatus', 'minestatus.net'],
['MisterLauncher', 'misterlauncher.org'],
['MinecraftServersDe', 'minecraft-servers.de'],
['DiscordBoats', 'discord.boats'],
['ServerListGames', 'serverlist.games'],
['BestMinecraftServers', 'best-minecraft-servers.co'],
['MinecraftServers100', 'minecraftservers100.com'],
['MCServerListCZ', 'mc-serverlist.cz'],
['MineServers', 'mineservers.com'],
['ATLauncher', 'atlauncher.com'],
['ServersMinecraft', 'servers-minecraft.net'],
['MinecraftListCZ', 'minecraft-list.cz'],
['ListeServeursMinecraft', 'liste-serveurs-minecraft.org'],
['MCServidores', 'mcservidores.com'],
['XtremeTop100', 'xtremetop100.com'],
['MinecraftServerSk', 'minecraft-server.sk'],
['ServeursMinecraftOrg', 'serveursminecraft.org'],
['ServeursMCNet', 'serveurs-mc.net'],
['ServeursMinecraftCom', 'serveur-minecraft.com'],
['ServeurMinecraftVoteFr', 'serveur-minecraft-vote.fr'],
['MineBrowseCom', 'minebrowse.com'],
['MCServerListCom', 'mc-server-list.com'],
['ServerLocatorCom', 'serverlocator.com'],
['TopMmoGamesRu', 'top-mmogames.ru'],
['MmoRpgTop', 'mmorpg.top'],
['MmoVoteRu', 'mmovote.ru'],
['McMonitoringInfo', 'mc-monitoring.info'],
['McServerTimeCom', 'mcservertime.com'],
['ListeServeursFr', 'liste-serveurs.fr'],
['ServeurMinecraftFr', 'serveur-minecraft.fr'],
['MineServTop', 'mineserv.top'],
['Top100ArenaCom', 'top100arena.com'],
['MinecraftBestServersCom', 'minecraftbestservers.com'],
['MCLikeCom', 'mclike.com'],
['PixelmonServerListCom', 'pixelmon-server-list.com'],
['MinecraftServerSk2', 'minecraftserver.sk'],
['ServidoresdeMinecraftEs', 'servidoresdeminecraft.es'],
['MinecraftSurvivalServersCom', 'minecraftsurvivalservers.com'],
['MinecraftGlobal', 'minecraft.global'],
['Warface', 'warface.com'],
['CurseForge', 'curseforge.com'],
['HoYoLAB', 'hoyolab.com'],
['TrackingServers', 'trackingservers.cloud'],
['McListIo', 'mclist.io'],
['LoliLand', 'loliland.ru'],
['MCServersTOP', 'mcservers.top'],
['Discadia', 'discadia.com'],
['MinecraftSurvivalServers', 'minecraftsurvivalservers.net'],
['TopServersCom', 'topservers.com'],
['GenshinDrop', 'genshindrop.com'],
['EmeraldServers', 'emeraldservers.com'],
['ServidoresMC', '40servidoresmc.es'],
['MinecraftServersBiz2', 'minecraft-servers.biz'],
['TopMCServersNet', 'top-mc-servers.net'],
['MinecraftServerListCom', 'minecraft-serverlist.com'],
['FindMCServer', 'findmcserver.com'],
['ServeurListe', 'serveurliste.com'],
['CraftBook', 'craftbook.cz'],
['RovelStars', 'rovelstars.com'],
['InfinityBots', 'infinitybots.gg'],
['BotListMe', 'botlist.me'],
['TopMinecraftIo', 'topminecraft.io'],
['MineListNet', 'minelist.net'],
['ListeServMinecraftFr', 'liste-serv-minecraft.fr'],
['PlayMinecraftServersCom', 'play-minecraft-servers.com'],
['MinecraftMenu', 'minecraft.menu'],
['Custom', 'Custom']
])
let cursor = await transaction.objectStore('projects').openCursor()
while (cursor) {
const project = cursor.value
const domain = oldNames.get(project.rating)
const voteURL = allProjects[domain]?.voteURL?.(project)
if (!domain || !voteURL) {
console.warn('When updating the database, it was not possible to find information on rating, additional information:', JSON.stringify(project), 'domain', domain, 'voteURL', voteURL)
await cursor.delete()
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
continue
}
const domain2 = getDomainWithoutSubdomain(voteURL)
if (domain2 && domain !== domain2 && domain !== 'Custom') {
project.rating = domain2
project.ratingMain = domain
} else {
project.rating = domain
}
if (project.rating === 'topg.org') {
// noinspection JSCheckFunctionSignatures
if (!isNaN(project.id.at(0))) {
project.id = 'server-' + project.id
}
} else if (project.rating === 'minecraftrating.ru' || project.rating === 'top.gg' || project.rating === 'discordbotlist.com' || project.rating === 'discords.com' || project.rating === 'misterlauncher.org') {
project.listing = project.game
delete project.game
} else if (project.rating === 'minecraftkrant.nl') {
if (!project.game) project.game = 'www.minecraftkrant.nl'
project.lang = project.game
delete project.game
}
if (((project.rating === 'topcraft.club' || project.rating === 'topcraft.ru') && project.id === '7666') || (project.id === 'arago' && (project.rating === 'minecraftrating.ru' || project.rating === 'tmonitoring.com'))) {
project.error = chrome.i18n.getMessage('disabledSite', 'Проект закрыт')
project.time = Infinity
}
if (project.rating === 'craftlist.org') {
project.error = chrome.i18n.getMessage('disabledSite','There is a high risk of being blocked for auto-voting, vote on this site manually')
project.time = Infinity
}
if (project.key == null) {
project.key = cursor.key
}
// noinspection JSUnresolvedReference
delete project.openedTimeoutQueue
// noinspection JSUnresolvedReference
delete project.openedNextAttempt
// noinspection JSUnresolvedReference
delete project.openedCountInject
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
}
}
if (oldVersion <= 14) {
let cursor = await transaction.objectStore('projects').index('rating').openCursor('topcraft.club')
while (cursor) {
const project = cursor.value
project.error = chrome.i18n.getMessage('disabledSite','Высокий риск быть заблокированным за авто-голосование, голосуйте на данном сайте вручную')
project.time = Infinity
await cursor.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor = await cursor.continue()
if (!cursor) cursor = await transaction.objectStore('projects').index('rating').openCursor('topcraft.ru')
}
let cursor2 = await transaction.objectStore('projects').index('rating').openCursor('mctop.su')
while (cursor2) {
const project = cursor2.value
project.error = chrome.i18n.getMessage('disabledSite','Высокий риск быть заблокированным за авто-голосование, голосуйте на данном сайте вручную')
project.time = Infinity
await cursor2.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor2 = await cursor2.continue()
}
let cursor3 = await transaction.objectStore('projects').index('rating').openCursor('monitoringminecraft.ru')
while (cursor3) {
const project = cursor3.value
project.error = chrome.i18n.getMessage('disabledSite','Сайт не работает')
project.time = Infinity
await cursor3.update(project)
// noinspection JSVoidFunctionReturnValueUsed
cursor3 = await cursor3.continue()
}
}
if (!todayStats) {
const other = transaction.objectStore('other')
todayStats = {
successVotes: 0,
errorVotes: 0,
laterVotes: 0,
lastSuccessVote: null,
lastAttemptVote: null
}
await other.put(todayStats, 'todayStats')
}
if (!generalStats) {
const other = transaction.objectStore('other')
generalStats = {
successVotes: 0,
monthSuccessVotes: 0,
lastMonthSuccessVotes: 0,
errorVotes: 0,
laterVotes: 0,
lastSuccessVote: null,
lastAttemptVote: null,
added: Date.now()
}
await other.put(generalStats, 'generalStats')
}
}