-
Notifications
You must be signed in to change notification settings - Fork 5
/
global.js
executable file
·42 lines (33 loc) · 943 Bytes
/
global.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
/* globals page */
"use strict";
const EXTENSION_NAME = "KeePassXC-Mail";
const AssociatedAction = {
NOT_ASSOCIATED: 0,
ASSOCIATED: 1,
NEW_ASSOCIATION: 2,
CANCELED: 3
};
function tr(key, params) {
return browser.i18n.getMessage(key, params);
}
// Returns file name and line number from error stack
const getFileAndLine = function() {
const err = new Error().stack.split("\n");
const line = err[4] ?? err[err.length - 1];
const result = line.substring(line.lastIndexOf("/") + 1, line.lastIndexOf(":"));
return result;
};
const debugLogMessage = function(message, extra) {
console.log(`[Debug ${getFileAndLine()}] ${EXTENSION_NAME} - ${message}`);
if (extra) {
console.log(extra);
}
};
const logDebug = function(message, extra) {
if (page.settings.debugLogging) {
debugLogMessage(message, extra);
}
};
const logError = function(message) {
console.log(`[Error ${getFileAndLine()}] ${EXTENSION_NAME} - ${message}`);
};