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