forked from AnneTrue/nexus-clash-interface-tweaks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
zalgofy.js
135 lines (118 loc) · 4.98 KB
/
zalgofy.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const zalgofy = {
module: async (api) => {
const mod = await api.registerModule(
'zalgofy',
'Zalgo Speech',
'local',
'Z A L G O S P E E C H',
);
const randIndex = (length) => Math.floor(Math.random() * length);
// Based off https://github.com/casieber/zalgo-js
const zalgo = {
up : [
768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783,
784, 785, 786, 787, 788, 789, 794, 795, 829, 830, 831, 832, 833, 834, 835, 836,
838, 842, 843, 844, 848, 849, 850, 855, 856, 859, 861, 862, 864, 865, 867, 868,
869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879
],
middle : [
820, 821, 822, 823, 824
],
down : [
790, 791, 792, 793, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807,
808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 825, 826, 827, 828,
837, 839, 840, 841, 845, 846, 851, 852, 853, 854, 857, 858, 860, 863, 866
]
};
const zalgofyString = (string, settings) => {
if (!settings) settings = {};
const defaultSettings = {
up: true, middle: true, down: true, intensity: 3
};
for (const key of Object.keys(defaultSettings)) if (!settings[key]) settings[key] = defaultSettings[key];
const directions = Object.keys(zalgo).reduce((acc, value) => (settings[value] ? [...acc, value] : acc), []);
if (directions.length === 0) return string;
let HECOMES = '';
for (const char of Array.from(string)) {
HECOMES += char;
for (let i = 0; i < settings.intensity; i++) {
const direction = directions[randIndex(directions.length)];
HECOMES += String.fromCharCode(zalgo[direction][randIndex(zalgo[direction].length)]);
}
}
return HECOMES;
}
const zalgofyForm = (form, settings) => {
const textInput = form.querySelector('input[type="text"]');
const speechButton = form.querySelector('input[type="submit"]');
const newSpeechButton = speechButton.cloneNode();
newSpeechButton.disabled = false;
speechButton.type = 'button';
speechButton.classList.add('hidden');
form.insertBefore(newSpeechButton, speechButton);
const emoteRE = new RegExp(String.raw`^/(?<code>\w+)(?<tail>.*?)$`);
newSpeechButton.onclick = function() {
const emoteMatch = textInput.value.match(emoteRE);
if (!emoteMatch) textInput.value = zalgofyString(textInput.value, settings);
else {
const code = emoteMatch.groups.code.toLowerCase();
const tail = emoteMatch.groups.tail;
if (code === 'em' || code === 'me') textInput.value = '/em' + tail;
else if (code === 'plain') textInput.value = tail;
else if (code === 'zalgo') textInput.value = zalgofyString(tail, settings);
else ;
}
speechButton.click();
}
}
const zalgofy = async (mod) => {
'use strict';
const settings = {
up: await mod.getSetting('zalgo-up'),
middle: await mod.getSetting('zalgo-middle'),
down: await mod.getSetting('zalgo-down'),
intensity: Number(await mod.getSetting('zalgo-intensity'))
};
const speakForm = document.querySelector('form[name="speak"]');
const bullForm = document.querySelector('form[name="bullhorn"]');
const writeForm = document.querySelector('form[name="writing"]');
if (speakForm) zalgofyForm(speakForm, settings);
if (bullForm) zalgofyForm(bullForm, settings);
if (writeForm) zalgofyForm(writeForm, settings);
}
await mod.registerSetting(
'checkbox',
'zalgo-up',
'Zalgo up',
''
);
await mod.registerSetting(
'checkbox',
'zalgo-middle',
'Zalgo middle',
''
);
await mod.registerSetting(
'checkbox',
'zalgo-down',
'Zalgo down',
''
);
await mod.registerSetting(
'select',
'zalgo-intensity',
'Zalgo Intensity',
'Choose how Zalgo you want to Zalgo',
[{'value' : '1', 'text' : '1'},
{'value' : '2', 'text' : '2'},
{'value' : '3', 'text' : '3'},
{'value' : '4', 'text' : '4'},
{'value' : '5', 'text' : '5'},
]
);
await mod.registerMethod(
'async',
zalgofy
);
}
}