-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenabled.local.js
More file actions
74 lines (66 loc) · 2.08 KB
/
enabled.local.js
File metadata and controls
74 lines (66 loc) · 2.08 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Translation from 'src/structures/constants/translation.ts';
import { buttonCSS as css } from 'src/utils/1.variables.js';
import wrap from 'src/utils/2.pokemon.js';
import { registerModule } from 'src/utils/plugin.js';
import * as settings from 'src/utils/settings/index.js';
// TODO: translation
const enable = ['Enabled with toast', 'Enabled silently'];
const setting = settings.register({
// TODO: translation
name: 'New plugin behavior',
key: 'underscript.plugins.init',
category: 'Plugins',
// TODO: translation
data: [...enable, 'Disabled with toast', 'Disabled silently'],
type: 'select',
});
wrap(() => {
const name = 'enabled';
function mod(plugin) {
if (!plugin.version) return;
const enabled = plugin.settings().add({
key: 'plugin.enabled',
// TODO: translation
name: 'Enabled',
default: enable.includes(setting.value()),
});
Object.defineProperty(plugin, name, {
get: () => enabled.value(),
});
const registered = plugin.settings().add({ key: 'plugin.registered', hidden: true });
if (registered.value()) return;
if (!setting.value().includes('toast')) {
registered.set(true);
return;
}
plugin.events.on(':load', () => {
const isEnabled = enabled.value();
plugin.toast({
// TODO: translation
title: 'New Plugin Detected',
text: `"${plugin.name}" has been <span class="${isEnabled ? 'green' : 'gray'}">${isEnabled ? 'enabled' : 'disabled'}</span> by default.`,
error: true, // Make it red.
className: {
toast: 'dismissable',
button: 'dismiss',
},
buttons: [{
text: Translation.General(isEnabled ? 'disable' : 'enable'),
css,
onclick() {
enabled.set(!isEnabled);
registered.set(true);
},
}, {
text: Translation.DISMISS,
css,
onclick() {
enabled.set(isEnabled);
registered.set(true);
},
}],
});
});
}
registerModule(name, mod, ['settings', 'events']);
});