Skip to content

Commit 14d4555

Browse files
committed
Merge branch 'allowcharacters' of https://github.com/treeben77/automod-regex-generator
2 parents 3cd7eae + f3818d5 commit 14d4555

File tree

5 files changed

+376
-2
lines changed

5 files changed

+376
-2
lines changed

generators.js

+105-1
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,108 @@ function generateLeetspeakRegex(text, settings) {
274274
}
275275
}
276276

277-
export { generateLeetspeakRegex }
277+
const REGEX_CHARACTER_SETS = [
278+
{
279+
setting_bitwise: 2,
280+
value: function(settings) {
281+
if (!(settings & 8)) {
282+
return "a-zA-Z";
283+
} else {return ""};
284+
},
285+
essential: true
286+
},
287+
{
288+
setting_bitwise: 4,
289+
value: function(settings) {
290+
if (!(settings & 8)) {
291+
return "0-9";
292+
} else {return ""};
293+
},
294+
essential: true
295+
},
296+
{
297+
setting_bitwise: 8,
298+
value: function(settings) {
299+
if (settings & 2 && settings & 4) {
300+
return "\\p{ASCII}";
301+
} else if (settings & 2) {
302+
return "\\p{ASCII}--[0-9]";
303+
} else if (settings & 4) {
304+
return "\\p{ASCII}--[a-zA-Z]";
305+
} else {
306+
return "\\p{ASCII}--[a-zA-Z0-9]";
307+
}
308+
},
309+
essential: true
310+
},
311+
{
312+
setting_bitwise: 16,
313+
value: "€…†‡‘’“”•–—™¢£¤¥¦§©®°±²³µ¶¹"
314+
},
315+
{
316+
setting_bitwise: 32,
317+
value: function(settings) {
318+
if (settings & 16) {
319+
return "À-ÿŸ¿¡"
320+
} else {
321+
return "À-ÿŸ"
322+
}
323+
}
324+
},
325+
{
326+
setting_bitwise: 64,
327+
value: "\\p{Extended_Pictographic}\\u{200d}\\u{1f3fb}-\\u{1f3ff}\\u{1f1e6}-\\u{1f1ff}\\u{fe0f}"
328+
},
329+
{
330+
setting_bitwise: 128,
331+
value: "\\u{0400}-\\u{04ff}\\u{0500}-\\u{052f}\\u{a640}-\\u{a69f}\\u{1e030}-\\u{1e08f}\\u{1d2b}-\\u{1d78}\\u{fe2e}-\\u{fe2f}"
332+
},
333+
{
334+
setting_bitwise: 256,
335+
value: "\\u{3000}-\\u{303f}\\u{3040}-\\u{309f}\\u{30a0}-\\u{30ff}\\u{ff00}-\\u{ff9f}\\u{4e00}-\\u{9faf}\\u{3400}-\\u{4dbf}"
336+
},
337+
{
338+
setting_bitwise: 512,
339+
value: "\\u{0621}-\\u{064b}\\u{0660}-\\u{0669}"
340+
}
341+
]
342+
343+
function generateCharacterTypeRegex(settings) {
344+
let character_sets = [];
345+
let violates_essential = false;
346+
347+
for (var i = 0; i < REGEX_CHARACTER_SETS.length; i++) {
348+
let character_set = REGEX_CHARACTER_SETS[i];
349+
350+
if (settings & character_set.setting_bitwise) {
351+
if (typeof character_set.value === 'function') {
352+
character_sets.push(character_set.value(settings));
353+
} else {
354+
character_sets.push(character_set.value);
355+
};
356+
if (character_set.essential && !(settings & 1)) {
357+
violates_essential
358+
}
359+
}
360+
};
361+
362+
let end_text
363+
if (settings & 1) {
364+
end_text = `[^${character_sets.join('')}]`;
365+
if (!character_sets.length) {
366+
end_text = `.`;
367+
};
368+
} else {
369+
end_text = `[${character_sets.join('')}]`;
370+
if (!character_sets.length) {
371+
end_text = ``;
372+
};
373+
}
374+
375+
return {
376+
regex: end_text,
377+
too_long: end_text.length > 260
378+
};
379+
};
380+
381+
export { generateLeetspeakRegex, generateCharacterTypeRegex }

static/main.css

+19
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ button {
191191
color: #f38688;
192192
}
193193

194+
.smaller-grid-items {
195+
flex-basis: 20%;
196+
}
197+
198+
.smaller-grid-items .grid-item {
199+
flex-basis: 20%;
200+
padding-bottom: 15px;
201+
}
202+
194203
.grid-row {
195204
margin-top: 15px;
196205
margin: 10px auto;
@@ -437,6 +446,16 @@ h4 {
437446
padding: 5px;
438447
}
439448

449+
select {
450+
font-family: 'Poppins', sans-serif;
451+
background-color: #151515;
452+
color: white;
453+
border-style: none;
454+
border-radius: 10px;
455+
height: 30px;
456+
padding: 0 5px;
457+
}
458+
440459
@media (pointer:coarse) {
441460
.header {
442461
padding: 15px;

static/regexes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ const regex_types = [
9898
copy_btn: document.getElementById("copy-regex-invite-links"),
9999
output: document.getElementById("regex-output-invite-links"),
100100
generator: function(settings) {
101+
const main_invites = `(?:https?:\\/\\/)?(?:www\\.|ptb\\.|canary\\.)?(?:discord(?:app)?\\.(?:(?:com|gg)\\/(?:invite|servers)\\/+[a-z0-9-_]+)|discord\\.gg\\/+[a-z0-9-_]+)`;
101102
if (settings.third_party.checked) {
102-
return "(?:https?://)?(?:www.|ptb.|canary.)?(?:dsc\\.gg|invite\\.gg|discord\\.link|(?:discord\\.(?:gg|io|me|li|id))|disboard\\.org|discord(?:app)?\\.(?:com|gg)/(?:invite|servers))/[a-z0-9-_]+";
103+
return `${main_invites}|(?:https?://)?(?:www\\.)?(?:dsc\\.gg|invite\\.gg+|discord\\.link|(?:discord\\.(gg|io|me|li|id))|disboard\\.org)/[a-z0-9-_/]+`;
103104
} else {
104105
return `(?:https?://)?(?:www.|ptb.|canary.)?(?:discord\\.gg|discord(?:app)?\\.(?:com|gg)/(?:invite|servers))/[a-z0-9-_]+`;
105106
};

static/unicode.js

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// MIT License
2+
3+
// Copyright (c) 2023 - 2024 treeben77
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
import { generateCharacterTypeRegex } from "../generators.js";
24+
25+
const output = document.getElementById("regex-output");
26+
const whitelist_mode = document.getElementById("whitelist-mode");
27+
const error_length = document.getElementById("regex-error-toolong");
28+
const reset_settings = document.getElementById("reset-settings");
29+
const copy_output = document.getElementById("copy-regex");
30+
31+
const checkbox_let = document.getElementById("filter-let");
32+
const checkbox_num = document.getElementById("filter-num");
33+
const checkbox_asc = document.getElementById("filter-asc");
34+
const checkbox_sym = document.getElementById("filter-sym");
35+
const checkbox_acc = document.getElementById("filter-acc");
36+
const checkbox_emo = document.getElementById("filter-emo");
37+
const checkbox_cyr = document.getElementById("filter-cyr");
38+
const checkbox_kaj = document.getElementById("filter-kaj");
39+
const checkbox_arb = document.getElementById("filter-arb");
40+
41+
function updateRegex() {
42+
copy_output.innerText = "Copy"
43+
44+
var settings = 0;
45+
settings += (whitelist_mode.value == "allow") << 0
46+
settings += checkbox_let.checked << 1
47+
settings += checkbox_num.checked << 2
48+
settings += checkbox_asc.checked << 3
49+
settings += checkbox_sym.checked << 4
50+
settings += checkbox_acc.checked << 5
51+
settings += checkbox_emo.checked << 6
52+
settings += checkbox_cyr.checked << 7
53+
settings += checkbox_kaj.checked << 8
54+
settings += checkbox_arb.checked << 9
55+
56+
location.hash = btoa(JSON.stringify({
57+
s: settings
58+
})).replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '')
59+
60+
let generated = generateCharacterTypeRegex(settings)
61+
62+
error_length.hidden = !generated.too_long
63+
output.innerText = generated.regex;
64+
}
65+
66+
reset_settings.onclick = function() {
67+
whitelist_mode.value = "allow"
68+
checkbox_let.checked = true;
69+
checkbox_num.checked = true;
70+
checkbox_asc.checked = true;
71+
checkbox_sym.checked = true;
72+
checkbox_acc.checked = true;
73+
checkbox_emo.checked = true;
74+
checkbox_cyr.checked = false;
75+
checkbox_kaj.checked = false;
76+
checkbox_arb.checked = false;
77+
updateRegex();
78+
};
79+
80+
copy_output.onclick = function() {
81+
navigator.clipboard.writeText(output.innerText);
82+
copy_output.innerText = "Copied!";
83+
setTimeout(function() {
84+
copy_output.innerText = "Copy"
85+
}, 5000);
86+
}
87+
88+
// input.oninput = updateRegex
89+
checkbox_let.onchange = updateRegex
90+
checkbox_num.onchange = updateRegex
91+
checkbox_asc.onchange = updateRegex
92+
checkbox_sym.onchange = updateRegex
93+
checkbox_acc.onchange = updateRegex
94+
checkbox_emo.onchange = updateRegex
95+
checkbox_cyr.onchange = updateRegex
96+
checkbox_kaj.onchange = updateRegex
97+
checkbox_arb.onchange = updateRegex
98+
whitelist_mode.onchange = updateRegex
99+
100+
if (location.hash.length > 1) {
101+
const data = JSON.parse(atob(location.hash.replace("#", "").replace('_', '/').replace('-', '+')));
102+
103+
checkbox_let.checked = data.s & 2
104+
checkbox_num.checked = data.s & 4
105+
checkbox_asc.checked = data.s & 8
106+
checkbox_sym.checked = data.s & 16
107+
checkbox_acc.checked = data.s & 32
108+
checkbox_emo.checked = data.s & 64
109+
checkbox_cyr.checked = data.s & 128
110+
checkbox_kaj.checked = data.s & 256
111+
checkbox_arb.checked = data.s & 512
112+
if (data.s & 1) {
113+
whitelist_mode.value = "allow"
114+
} else {
115+
whitelist_mode.value = "block"
116+
}
117+
}
118+
119+
updateRegex()

0 commit comments

Comments
 (0)