-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathlogger.ts
More file actions
52 lines (44 loc) · 1.01 KB
/
logger.ts
File metadata and controls
52 lines (44 loc) · 1.01 KB
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
/**
* Copyright (c) 2021 Hengyang Zhang
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
const STORAGE_KEY = "_logOpen"
const STORAGE_VAL = "1"
let OPEN_LOG = false
// localStorage is not undefined in mv3 of service worker
function initOpenLog() {
try {
localStorage.getItem(STORAGE_KEY) === STORAGE_VAL
} catch (ignored) { }
}
function updateLocalStorage(openState: boolean) {
try {
openState
? localStorage.setItem(STORAGE_KEY, STORAGE_VAL)
: localStorage.removeItem(STORAGE_KEY)
} catch (ignored) { }
}
initOpenLog()
/**
* @since 0.0.4
* @param args arguments
*/
export function log(...args: any) {
OPEN_LOG && console.log(...args)
}
/**
* @since 0.0.4
*/
export function openLog(): string {
updateLocalStorage(OPEN_LOG = true)
return 'Opened the log manually.'
}
/**
* @since 0.0.8
*/
export function closeLog(): string {
updateLocalStorage(OPEN_LOG = false)
return 'Closed the log manually.'
}