-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.js
93 lines (80 loc) · 2.13 KB
/
event.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
'use strict';
import browser from "webextension-polyfill";
import { newId } from './utils';
let scope = 'event_types_name_';
const Types = {
'runtime.startup': {
name: browser.i18n.getMessage(`${scope}runtimeStartup`)
},
'download.new': {
name: browser.i18n.getMessage(`${scope}downloadNew`)
},
'download.completed': {
name: browser.i18n.getMessage(`${scope}downloadCompleted`)
},
'download.failure': {
name: browser.i18n.getMessage(`${scope}downloadFailure`)
},
'download.interrupted': {
name: browser.i18n.getMessage(`${scope}downloadInterrupted`)
},
'navigation.backForward': {
name: browser.i18n.getMessage(`${scope}navigationBackForward`),
permissions: ['webNavigation']
},
'request.completed': {
name: browser.i18n.getMessage(`${scope}requestCompleted`),
permissions: ['webRequest'],
slots: [
{
name: 'filter_statusCode'
}
]
},
'window.cut': {
name: browser.i18n.getMessage(`${scope}windowCut`),
forContent: true
},
'window.copy': {
name: browser.i18n.getMessage(`${scope}windowCopy`),
forContent: true
}
};
class EventSetting {
constructor(config) {
this.id = config ? config.id : newId();
this.name = config ? config.name : '';
this.type = config ? config.type : null;
this.options = config ? config.options : {};
this.soundId = config ? config.soundId : null;
this.enabled = config ? config.enabled : false;
}
static get Types() {
return Types;
}
toPersistedProps() {
let obj = {
id: this.id,
name: this.name || '',
type: this.type,
options: this.options,
soundId: this.soundId,
enabled: this.enabled
}
return obj;
}
static getTypeDef(type, prop) {
let def = this.Types[type];
switch (prop) {
case 'forContent':
return Boolean(def?.forContent);
case 'name':
return def ? def.name : '';
case 'permissions':
return (def && 'permissions' in def) ? def.permissions : [];
case 'slots':
return (def && 'slots' in def) ? def.slots : [];
}
}
}
export { EventSetting, Types };