Skip to content

Commit c45bd02

Browse files
committed
feat: check function for plugins to utilize
1 parent ae7825c commit c45bd02

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/checker.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// eslint-disable-next-line no-unused-vars
2+
function checkUnderscript(pluginName) {
3+
if (window.underscript) return;
4+
5+
const key = 'underscript.required';
6+
if (sessionStorage.getItem(key)) return;
7+
sessionStorage.setItem(key, '1'); // Set instantly to prevent multiple alerts happening
8+
const message = "Looks like you don't have UnderScript installed, or you deactivated it! In order for plugins to work, you need to have it up and running. Until then, the features of this userscript will simply not work. Thank you for your understanding.";
9+
10+
let alerted = true;
11+
if (window.SimpleToast) {
12+
SimpleToast({
13+
title: 'Missing Requirements',
14+
text: message,
15+
footer: pluginName,
16+
});
17+
} else if (window.BootstrapDialog) {
18+
BootstrapDialog.show({
19+
title: 'Oh No!',
20+
type: BootstrapDialog.TYPE_WARNING,
21+
message,
22+
buttons: [{
23+
label: 'Proceed',
24+
cssClass: 'btn-primary',
25+
action(dialog) {
26+
dialog.close();
27+
},
28+
}],
29+
});
30+
} else {
31+
alerted = false;
32+
}
33+
34+
if (!alerted) sessionStorage.removeItem(key);
35+
36+
throw new Error(`${pluginName}: UnderScript required`);
37+
}

0 commit comments

Comments
 (0)