-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctions.js
More file actions
104 lines (104 loc) · 2.7 KB
/
functions.js
File metadata and controls
104 lines (104 loc) · 2.7 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const fn = {
decode: function (string) {
return $('<textarea>').html(string).val();
},
each: function (o, f, t) {
if (!o) return;
Object.keys(o).forEach(function (x) {
f.call(t, o[x], x, o); // "this", value, key, object
});
},
pingRegex: (() => {
const filter = /(\||\\|\(|\)|\*|\+|\?|\.|\^|\$|\[|\{|\})/g
function filterMeta(text) {
return text.replace(filter, '\\$1');
}
function build() {
if (!selfUsername) console.log('Warning: Username not set');
const exp = `\\b((?:${[selfUsername].concat(settings.value('underscript.ping.extras')).map(filterMeta).join(')|(?:')}))(?!.*">)\\b`;
return new RegExp(exp, 'gi');
}
return build;
})(),
toast: (arg) => {
// Why do I even check for SimpleToast? It *has* to be loaded at this point...
if (!window.SimpleToast || !arg) return false;
if (typeof arg === 'string') {
arg = {
text: arg,
};
}
const defaults = {
footer: 'via UnderScript',
css: {
'background-color': 'rgba(0,5,20,0.6)',
'text-shadow': '',
'font-family': 'monospace',
footer: {
'text-align': 'end',
},
},
};
return new SimpleToast(fn.merge(defaults, arg));
},
ignoreUser: (name, key) => {
settings.register({
key, name,
type: 'remove',
page: 'Chat',
category: 'Ignored Users',
});
},
infoToast: (arg, key, val) => {
if (localStorage.getItem(key) === val) return null;
if (typeof arg === 'string') {
arg = {
text: arg,
};
} else if (typeof arg !== 'object') return null;
const override = {
onClose: (reason) => {
if (arg.onClose) {
arg.onClose(reason);
}
localStorage.setItem(key, val);
},
};
const defaults = {
title: 'Did you know?',
css: {
'font-family': 'inherit',
},
};
return fn.toast(fn.merge(defaults, arg, override));
},
merge: (...obj) => {
const ret = {};
if (obj) {
obj.forEach((o) => {
fn.each(o, (val, key) => {
ret[key] = typeof val === 'object' ? fn.merge(ret[key], val) : val;
});
});
}
return ret;
},
debug: (arg, permission = 'debugging') => {
if (typeof arg === 'string') {
arg = {
text: arg,
};
}
const defaults = {
background: '#c8354e',
textShadow: '#e74c3c 1px 2px 1px',
css: {'font-family': 'inherit'},
button: {
// Don't use buttons, mouseOver sucks
background: '#e25353',
textShadow: '#46231f 0px 0px 3px',
},
};
return localStorage.getItem(permission) === 'true' && fn.toast(fn.merge(defaults, arg));
},
};