/
autosave-sessions.js
659 lines (571 loc) · 21.6 KB
/
autosave-sessions.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
/*
* Autosave Sessions (a mod for Vivaldi)
* Written by LonM, modified by boroda74
* No Copyright Reserved
*
* V4.1: Attempt to retry if settings is not ready
* v4 : Localise to current timezone, l10n
* v3 : Has own settings section & support private windows again
* v2 : Better handling of multiple windows
*
* ru-RU translation by @boroda74
*/
(function autoSaveSessionsMod(){
"use strict";
var TimerId = -1;
var AutosaveInterval = 0;
var OldAutosaveInterval = -1;
var AutosaveOdd = true;
var OldAutosaveOdd = false;
var ProcessAutosaveOdd = true;
var ProcessAutosaveEven = false;
var OddEvenSwitchingProcessed = true;
var CurrentWindowIsPrivate = false;
var AutosaveTimeout = 0;
const NullDate = Date.parse("2000-01-01");
var LastSaveTime = NullDate;
const OneMinuteInterval = 60 * 1000; //60 sec.
const UpdateSettingsInterval = 60 * 1000; //Default - 60 sec., but can be changed
const PrivateWindowsNotSavedFilenamePostfix = '!';
const PrivateWindowsOnlyFilenamePostfix = '!!';
const LANGUAGES = new Array();
var LANGUAGE;
const l10n = {
'en-GB': {
language_name: 'English (UK English) \u2002\u2002', //Two Em-spaces at the end are to equalize language dropdown width with other setting fields
mod_name: 'Autosave Sessions Mod',
language: '\nLanguage',
language_description: 'Select mod language',
autosave_interval: 'Period (minutes)',
autosave_interval_description: 'Set 0 to disable autosaving',
max_old_sessions: '\nOld Sessions Count',
max_old_sessions_description: 'Maximum number of autosaved sessions (old sessions will be deleted)',
prefix: '\nPrefix',
file_prefix: 'AUTO',
file_prefix_description: 'A unique prefix made up of the following characters: A-Z 0-9 _ - <space>',
save_private_windows: '\nSave Private Windows',
save_private_windows_description: 'Save opened private windows to separate session'
},
'ru-RU': {
language_name: 'Russian (Русский)',
mod_name: 'Мод автосохранения сессий',
language: '\nЯзык интефейса',
language_description: 'Выберите язык мода',
autosave_interval: 'Период (в минутах)',
autosave_interval_description: 'Установите 0, чтобы запретить автосохранение',
max_old_sessions: '\nКоличество хранимых сессий',
max_old_sessions_description: 'Максимальное число автосохраняемых сессий (старые будут удаляться)',
prefix: '\nПрефикс',
file_prefix: 'АВТО',
file_prefix_description: 'Уникальный префикс, содержащий символы: A-Z А-Я 0-9 _ - <пробел>',
save_private_windows: '\nСохранять приватные окна',
save_private_windows_description: 'Сохранять открытые приватные окна в отдельную сессию'
},
};
var CURRENT_SETTINGS = {};
/*
* Copied from bundle.js © Vivaldi - Check if a filename is valid
* @param {string} s
*/
function isValidName(e){
return /^[^\\/:\*\?"<>\|]+$/.test(e) && !/^\./.test(e) && !/^(nul|prn|con|lpt[0-9]|com[0-9])(\.|$)/i.test(e);
}
/*
* Turns a date into a string that can be used in a file name
* Locale string seems to be the best at getting the correct time for any given timezone
* @param {Date} date object
*/
function dateToFileSafeString(date){
const badChars = /[\\/:\*\?"<>\|]/gi;
let escaped = date.toLocaleString().replace(/:/g, "`");
escaped = escaped.substring(0, escaped.length - 3); //Remove seconds from session name
return escaped.replace(badChars, '.');
}
/*
* Enable Autosaving sessions
*/
function autoSaveSession(){
vivaldi.sessionsPrivate.getAll(allSessions => {
const keys = MOD_SETTINGS.reduce((prev, current) => {
prev[current.id] = current.default;
return prev;
}, {});
chrome.storage.local.get(keys, value => {
CURRENT_SETTINGS = value;
if(CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_DELAY_MINUTES"] === 0){
return;
}
const savePrivate = CURRENT_SETTINGS["LONM_SESSION_SAVE_PRIVATE_WINDOWS"];
if(CurrentWindowIsPrivate && !savePrivate){ //Will skip the check of 'savePrivate' later
return;
}
/* Create the new session */
chrome.windows.getAll({
populate: true,
windowTypes: ["normal"]
}, openedWindows => {
const prefix = CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_PREFIX"] + ' ';
const maxOld = CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_MAX_OLD_SESSIONS"];
let name = prefix + dateToFileSafeString(new Date());
let openedWindowsCount = openedWindows.length;
let privateWindowsCount = 0;
for(let i = 0; i < openedWindows.length; i++){
if(openedWindows[i].incognito){
privateWindowsCount++;
}
}
if(!CurrentWindowIsPrivate){
let sessionName;
if(privateWindowsCount > 0){
if(openedWindowsCount > privateWindowsCount){
sessionName = name + PrivateWindowsNotSavedFilenamePostfix;
} else {
sessionName = "";
}
} else {
sessionName = name;
}
if(sessionName !== ""){
/* Final sanity check */
if (!isValidName(sessionName)){
throw new Error('[Autosave Sessions] Cannot name a session as ' + sessionName);
}
vivaldi.sessionsPrivate.saveOpenTabs(sessionName, { saveOnlyWindowId: 0 }, () => {}); /* There is no way to tell if it failed */
/* Delete older (not private) sessions */
let autosavesOnly = allSessions.filter(x => x.name.indexOf(prefix) === 0).filter(x => x.name.substring(x.name.length - PrivateWindowsOnlyFilenamePostfix.length) !== PrivateWindowsOnlyFilenamePostfix);
let oldestFirst = autosavesOnly.sort((a,b) => {return a.createDateJS - b.createDateJS;});
let numberOfSessions = oldestFirst.length + 1; /* length + 1 as we have just added a new one */
let oldestIndex = 0;
while(numberOfSessions > maxOld){
vivaldi.sessionsPrivate.delete(oldestFirst[oldestIndex].name,() => {});
oldestIndex++;
numberOfSessions--;
}
}
}
if(CurrentWindowIsPrivate){ //Have checked 'savePrivate' earlier, so will skip this check
let sessionName = name + PrivateWindowsOnlyFilenamePostfix;
/* Final sanity check */
if (!isValidName(sessionName)){
throw new Error('[Autosave Sessions] Cannot name a session as ""' + sessionName + '""');
}
vivaldi.sessionsPrivate.saveOpenTabs(sessionName, { saveOnlyWindowId: 0 }, () => {}); /* There is no way to tell if it failed */
/* Delete older (private) sessions */
const autosavesOnly = allSessions.filter(x => x.name.indexOf(prefix) === 0).filter(x => x.name.substring(x.name.length - PrivateWindowsOnlyFilenamePostfix.length) === PrivateWindowsOnlyFilenamePostfix);
const oldestFirst = autosavesOnly.sort((a,b) => {return a.createDateJS - b.createDateJS;});
let numberOfSessions = oldestFirst.length + 1; /* length + 1 as we have just added a new one */
let oldestIndex = 0;
while(numberOfSessions > maxOld){
vivaldi.sessionsPrivate.delete(oldestFirst[oldestIndex].name,() => {});
oldestIndex++;
numberOfSessions--;
}
}
});
});
});
}
/*
* Check if this is the most recent window, and if the most recent window is still open
* if not, then stop saving the sessions
*/
function triggerAutosaveHelper(){
let lastWindowSettingName;
let lastSaveTimeSettingName;
if(!CurrentWindowIsPrivate){
lastWindowSettingName = "LONM_SESSION_AUTOSAVE_LAST_WINDOW";
lastSaveTimeSettingName = "LONM_SESSION_AUTOSAVE_LAST_DATETIME";
} else {
lastWindowSettingName = "LONM_SESSION_AUTOSAVE_LAST_PRIVATE_WINDOW";
lastSaveTimeSettingName = "LONM_SESSION_AUTOSAVE_LAST_PRIVATE_DATETIME";
}
chrome.storage.local.get([lastWindowSettingName, lastSaveTimeSettingName], lastSettings => {
let lastSavedWindow = lastSettings[lastWindowSettingName]; //Last window id when autosaving window has been changed
let lastSavedSaveTime = lastSettings[lastSaveTimeSettingName]; //Last datetime when autosaving window has been changed
const now = Date.now();
if(OldAutosaveInterval !== AutosaveInterval && AutosaveTimeout <= 0){ //If this function is called via setTimeout() then lets schedule periodic calls via setInterval() now
initSwitching();
}
if(lastSavedWindow == null){
lastSavedWindow = -1;
};
if(window.vivaldiWindowId === lastSavedWindow){
/* We know this window is correct, skip the checks */
LastSaveTime = now;
chrome.storage.local.set({
[lastSaveTimeSettingName]: LastSaveTime
}, () => {
autoSaveSession();
});
return;
}
chrome.windows.getAll(openedWindows => {
const foundLastOpen = openedWindows.find(windowItem => windowItem.id === lastSavedWindow);
if(foundLastOpen){
/* Most recent window still active, use that one instead (see code above) */
} else {
/* Most recent window was closed, revert to this one */
if(lastSavedSaveTime == null){
LastSaveTime = now;
} else if((now - lastSavedSaveTime) > AutosaveInterval){
LastSaveTime = now;
} else {
LastSaveTime = lastSavedSaveTime;
}
chrome.storage.local.set({
[lastWindowSettingName]: window.vivaldiWindowId, [lastSaveTimeSettingName]: LastSaveTime
}, () => {
if(LastSaveTime === now){
autoSaveSession();
} else { //Lets reschedule autosavings starting from new last save time
AutosaveTimeout = getTimeout();
initSwitching();
}
});
}
});
});
}
function getTimeout(){
let now = Date.now();
let timeout = 0;
if(LastSaveTime === NullDate){
// timeout = 0;
} else if(now - LastSaveTime < 0){
// timeout = 0;
} else {
timeout = AutosaveInterval - (now - LastSaveTime);
}
return timeout;
}
function updateSettings(){ //Periodically checks if settings has been changed in another window
const keys = MOD_SETTINGS.reduce((prev, current) => {
prev[current.id] = current.default;
return prev;
}, {});
chrome.storage.local.get(keys, value => {
CURRENT_SETTINGS = value;
let newAutosaveInterval = CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_DELAY_MINUTES"] * OneMinuteInterval;
if(AutosaveInterval !== newAutosaveInterval){
AutosaveInterval = newAutosaveInterval;
AutosaveTimeout = getTimeout();
initSwitching();
}
});
}
function triggerAutosaveOdd(){
if(ProcessAutosaveOdd){
OddEvenSwitchingProcessed = true;
triggerAutosaveHelper();
}
}
function triggerAutosaveEven(){
if(ProcessAutosaveEven){
OddEvenSwitchingProcessed = true;
triggerAutosaveHelper();
}
}
function processSwitchOddEven(){
if(OldAutosaveOdd !== AutosaveOdd){
OldAutosaveOdd = AutosaveOdd;
AutosaveOdd = !AutosaveOdd;
if(TimerId !== -1){
clearInterval(TimerId);
TimerId = -1;
}
if(AutosaveOdd){
ProcessAutosaveOdd = true;
ProcessAutosaveEven = false;
if(AutosaveTimeout > 1000){
setTimeout(triggerAutosaveOdd, AutosaveTimeout);
AutosaveTimeout = 0;
} else if(AutosaveInterval > 0){
TimerId = setInterval(triggerAutosaveOdd, AutosaveInterval);
AutosaveTimeout = 0;
OldAutosaveInterval = AutosaveInterval;
} else {
AutosaveTimeout = 0;
OldAutosaveInterval = AutosaveInterval;
OddEvenSwitchingProcessed = true;
LastSaveTime = NullDate;
}
} else {
ProcessAutosaveOdd = false;
ProcessAutosaveEven = true;
if(AutosaveTimeout > 1000){
setTimeout(triggerAutosaveEven, AutosaveTimeout);
AutosaveTimeout = 0;
} else if(AutosaveInterval > 0){
TimerId = setInterval(triggerAutosaveEven, AutosaveInterval);
AutosaveTimeout = 0;
OldAutosaveInterval = AutosaveInterval;
} else {
AutosaveTimeout = 0;
OldAutosaveInterval = AutosaveInterval;
OddEvenSwitchingProcessed = true;
LastSaveTime = NullDate;
}
}
}
}
function initSwitching(){
if(OddEvenSwitchingProcessed && (OldAutosaveInterval !== AutosaveInterval || AutosaveTimeout > 0)){
OddEvenSwitchingProcessed = false;
processSwitchOddEven();
}
}
/*
* Mod the settings page to show settings there
* Wait a little bit after a settings page has been opened and add settings in
*/
const SETTINGSPAGE = "chrome-extension://mpognobbkildjkofajifpdfhcoklimli/components/settings/settings.html?path=general";
function modSettingsPageListener(newTab){
if(newTab.url === SETTINGSPAGE || newTab.pendingUrl === SETTINGSPAGE){
setTimeout(modSettingsPage, 500);
}
}
function modSettingsPage(){
const keys = MOD_SETTINGS.reduce((prev, current) => {
prev[current.id] = current.default;
return prev;
}, {});
chrome.storage.local.get(keys, value => {
CURRENT_SETTINGS = value;
const settingSection = document.querySelector(".vivaldi-settings .settings-content section");
if(!settingSection){
setTimeout(modSettingsPage, 1000);
return;
}
let lonmAutosaveSessionsSettings = document.getElementById("lonmAutosaveSessionsSettings");
if(lonmAutosaveSessionsSettings){
lonmAutosaveSessionsSettings.parentNode.removeChild(lonmAutosaveSessionsSettings);
}
const settingsHTML = document.createElement("section");
settingsHTML.className = "setting-section";
settingsHTML.id = "lonmAutosaveSessionsSettings";
const settingsDiv = document.createElement("div");
settingsDiv.insertAdjacentHTML("beforeend", "<h2>" + l10n[LANGUAGE].mod_name + "</h2>");
MOD_SETTINGS.forEach(setting => {
settingsDiv.appendChild(makeSettingElement(setting));
});
settingsHTML.appendChild(settingsDiv);
settingSection.insertAdjacentElement("afterbegin", settingsHTML);
});
}
/*
* For a mod setting you need:
*
* A) Load it when the mod starts
* B) Make an option for it when settings is opened
* C) Change the saved and current state with new value when setting is changed
*
* Mod setting has:
* Key: string
* Default Value: string|int
* Description: string
*
* Don't forget to edit function initModUILocalization() if you add/remove mod settings!
*/
const MOD_SETTINGS = [ //Settings are not localized yet, will localize them later
{
id: "LONM_SESSION_AUTOSAVE_DELAY_MINUTES",
type: Number,
min: 0,
max: undefined,
default: 15,
},
{
id: "LONM_SESSION_AUTOSAVE_MAX_OLD_SESSIONS",
type: Number,
min: 1,
max: undefined,
default: 7,
},
{ //This dictionary must be 3d (#2 - 0, 1, 2) in array
id: "LONM_SESSION_AUTOSAVE_PREFIX",
type: String,
pattern: "[\\wа-яА-Я_\\-\\s]{0,20}",
default: "AUTO",
},
{
id: "LONM_SESSION_SAVE_PRIVATE_WINDOWS",
type: Boolean,
default: false,
},
{
id: "LONM_AUTOSAVE_SESSIONS_LANGUAGE",
type: String,
pattern: "[\\w_\\-]{2,5}",
default: "en-GB",
},
];
/*
* Handle a change to a setting input
* Should be bound in a listener to the setting object
* @param {InputEvent} input
*/
function settingUpdated(input){
let oldLanguageValue = CURRENT_SETTINGS["LONM_AUTOSAVE_SESSIONS_LANGUAGE"];
let oldPrefixIsDefault = (CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_PREFIX"] === MOD_SETTINGS[2].default);
if(input.target.type === "checkbox"){
CURRENT_SETTINGS[this.id] = input.target.checked;
} else {
input.target.checkValidity();
if(input.target.reportValidity() && input.target.value !== ""){
CURRENT_SETTINGS[this.id] = input.target.value;
}
}
if(this.id === "LONM_AUTOSAVE_SESSIONS_LANGUAGE" && oldLanguageValue !== CURRENT_SETTINGS[this.id]){
initModUILocalization();
if(oldPrefixIsDefault){
CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_PREFIX"] = MOD_SETTINGS[2].default;
}
}
chrome.storage.local.set({ [this.id]: CURRENT_SETTINGS[this.id], ["LONM_SESSION_AUTOSAVE_PREFIX"]: CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_PREFIX"] }, () => {
if(this.id === "LONM_SESSION_AUTOSAVE_DELAY_MINUTES"){
let newAutosaveInterval = CURRENT_SETTINGS[this.id] * OneMinuteInterval;
if(AutosaveInterval !== newAutosaveInterval){
AutosaveInterval = newAutosaveInterval;
AutosaveTimeout = getTimeout();
initSwitching();
}
} else if(this.id === "LONM_AUTOSAVE_SESSIONS_LANGUAGE" && oldLanguageValue !== CURRENT_SETTINGS[this.id]){
modSettingsPage();
}
});
}
/*
* Create an element for the current setting
* @param modSetting
*/
function makeSettingElement(modSetting){
const currentSettingValue = CURRENT_SETTINGS[modSetting.id];
const div = document.createElement("div");
div.className = "setting-single";
const title = document.createElement("h3");
title.innerText = modSetting.title;
div.appendChild(title);
if(modSetting.description !== ""){
const info = document.createElement("p");
info.className = "info";
info.innerText = modSetting.description;
div.appendChild(info);
}
if(modSetting.id === "LONM_AUTOSAVE_SESSIONS_LANGUAGE"){
const select = document.createElement("select");
select.id = "LONM_AUTOSAVE_LANGUAGE_SELECT";
for (let [lang_id, lang_dict] of Object.entries(l10n)){
let option = document.createElement("option");
option.value = lang_id;
option.text = lang_dict.language_name;
select.appendChild(option);
}
select.value = currentSettingValue;
select.addEventListener("change", settingUpdated.bind(modSetting));
const label = document.createElement("label");
label.setAttribute("for", select.id);
label.appendChild(select);
div.appendChild(label);
} else {
const input = document.createElement("input");
input.id = modSetting.id;
input.value = currentSettingValue;
input.autocomplete = "off";
input.autocapitalize = "off";
input.autocorrect = "off";
input.spellcheck = "off";
switch (modSetting.type){
case Number:
input.type = "number";
break;
case String:
input.type = "text";
break;
case Boolean:
input.type = "checkbox";
if(currentSettingValue){input.checked = "checked";}
break;
default:
throw Error("Unknown setting type!");
}
if(modSetting.max){input.max = modSetting.max;}
if(modSetting.min){input.min = modSetting.min;}
if(modSetting.pattern){input.pattern = modSetting.pattern;}
input.addEventListener("input", settingUpdated.bind(modSetting));
div.appendChild(input);
}
return div;
}
/*
* (Re)initialize localization of mod settings
*/
function initModUILocalization(){
LANGUAGE = CURRENT_SETTINGS["LONM_AUTOSAVE_SESSIONS_LANGUAGE"];
for(let i = 0; i < MOD_SETTINGS.length; i++){
let setting = MOD_SETTINGS[i];
switch (setting.id){
case ("LONM_SESSION_AUTOSAVE_DELAY_MINUTES"):
setting["title"] = l10n[LANGUAGE].autosave_interval;
setting["description"] = l10n[LANGUAGE].autosave_interval_description;
break;
case ("LONM_SESSION_AUTOSAVE_MAX_OLD_SESSIONS"):
setting["title"] = l10n[LANGUAGE].max_old_sessions;
setting["description"] = l10n[LANGUAGE].max_old_sessions_description;
break;
case ("LONM_SESSION_AUTOSAVE_PREFIX"):
setting["default"] = l10n[LANGUAGE].file_prefix;
setting["title"] = l10n[LANGUAGE].prefix;
setting["description"] = l10n[LANGUAGE].file_prefix_description;
break;
case ("LONM_SESSION_SAVE_PRIVATE_WINDOWS"):
setting["title"] = l10n[LANGUAGE].save_private_windows;
setting["description"] = l10n[LANGUAGE].save_private_windows_description;
break;
case ("LONM_AUTOSAVE_SESSIONS_LANGUAGE"):
setting["title"] = l10n[LANGUAGE].language;
setting["description"] = l10n[LANGUAGE].language_description;
break;
default:
break;
};
};
}
/*
* Init the mod, but only if we are not incognito, to maintain privacy.
* Save the window id in storage, and only use the most recent window to save sessions
*/
function init(){
if(window.vivaldiWindowId){
chrome.windows.getCurrent(windowItem => {
CurrentWindowIsPrivate = windowItem.incognito;
AutosaveInterval = CURRENT_SETTINGS["LONM_SESSION_AUTOSAVE_DELAY_MINUTES"] * OneMinuteInterval;
setInterval(updateSettings, UpdateSettingsInterval); //Periodically checks if settings has been changed in another window
initSwitching();
if(CURRENT_SETTINGS["LONM_AUTOSAVE_SESSIONS_LANGUAGE"] == null){
CURRENT_SETTINGS["LONM_AUTOSAVE_SESSIONS_LANGUAGE"] = "en-GB";
}
for (let [lang_id, lang_dict] of Object.entries(l10n)){
LANGUAGES.push(lang_id);
}
initModUILocalization();
chrome.tabs.onCreated.addListener(modSettingsPageListener);
});
} else {
setTimeout(init, 500);
}
}
/*
* Load the settings and call the initialiser function
*/
function loadSettingsAndInit(){
const keys = MOD_SETTINGS.reduce((prev, current) => {
prev[current.id] = current.default;
return prev;
}, {});
chrome.storage.local.get(keys, value => {
CURRENT_SETTINGS = value;
setTimeout(init, 500);
});
}
loadSettingsAndInit();
})();