@@ -2,53 +2,61 @@ window.addEventListener("DOMContentLoaded", () => {
22 const helpIcon = document . querySelector ( ".help" ) ;
33 const infoDiv = document . querySelector ( ".information" ) ;
44
5- helpIcon . addEventListener ( "click" , ( ) => {
6- infoDiv . style . display =
7- infoDiv . style . display === "none" ? "inherit" : "none" ;
8- } ) ;
5+ if ( helpIcon && infoDiv ) {
6+ helpIcon . addEventListener ( "click" , ( ) => {
7+ infoDiv . style . display =
8+ infoDiv . style . display === "none" ? "inherit" : "none" ;
9+ } ) ;
10+ }
911} ) ;
1012
1113window . addEventListener ( "DOMContentLoaded" , ( ) => {
12- const appIdInput = document . querySelector ( '#appid' ) ;
13- const apiKeyInput = document . querySelector ( '#apikey' ) ;
14- const saveButton = document . querySelector ( '#save-settings-button' ) ;
14+ const appIdInput = document . querySelector ( "#appid" ) ;
15+ const apiKeyInput = document . querySelector ( "#apikey" ) ;
16+ const saveButton = document . querySelector ( "#save-settings-button" ) ;
17+
18+ if ( appIdInput && apiKeyInput && saveButton ) {
19+ function isValidUUID ( uuid ) {
20+ const uuidRegex =
21+ / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 1 - 5 ] [ 0 - 9 a - f ] { 3 } - [ 8 9 a b ] [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 12 } $ / i;
22+ return uuid . length > 0 && uuidRegex . test ( uuid ) ; // Ensure it's not empty and matches regex
23+ }
1524
16- function isValidUUID ( uuid ) {
17- const uuidRegex = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 1 - 5 ] [ 0 - 9 a - f ] { 3 } - [ 8 9 a b ] [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 12 } $ / i;
18- return uuid . length > 0 && uuidRegex . test ( uuid ) ; // Ensure it's not empty and matches regex
19- }
25+ function isValidApiKey ( apiKey ) {
26+ const base64Regex =
27+ / ^ (?: [ A - Z a - z 0 - 9 + / ] { 4 } ) { 12 , } (?: [ A - Z a - z 0 - 9 + / ] { 2 } = = | [ A - Z a - z 0 - 9 + / ] { 3 } = ) ? $ / ; // At least 48 characters in Base64
28+ const opaqueTokenRegex = / ^ o s _ v [ 2 - 9 ] _ a p p _ [ 2 - 7 a - z ] { 56 , } $ / ;
29+ return (
30+ base64Regex . test ( apiKey ) || opaqueTokenRegex . test ( apiKey )
31+ ) ; // Ensure it's not empty and matches regex
32+ }
2033
21- function isValidApiKey ( apiKey ) {
22- const base64Regex = / ^ (?: [ A - Z a - z 0 - 9 + / ] { 4 } ) { 12 , } (?: [ A - Z a - z 0 - 9 + / ] { 2 } = = | [ A - Z a - z 0 - 9 + / ] { 3 } = ) ? $ / ; // At least 48 characters in Base64
23- const opaqueTokenRegex = / ^ o s _ v [ 2 - 9 ] _ a p p _ [ 2 - 7 a - z ] { 56 , } $ / ;
24- return ( base64Regex . test ( apiKey ) || opaqueTokenRegex . test ( apiKey ) ) ; // Ensure it's not empty and matches regex
25- }
34+ function updateValidationIcon ( input , isValid ) {
35+ const icon = input . parentElement . querySelector ( ".validation-icon" ) ;
36+ if ( icon ) {
37+ icon . textContent = isValid ? "✅" : "❌" ;
38+ }
39+ }
2640
27- function updateValidationIcon ( input , isValid ) {
28- const icon = input . parentElement . querySelector ( '.validation-icon' ) ;
29- if ( icon ) {
30- icon . textContent = isValid ? '✅' : '❌' ;
41+ function toggleSaveButton ( ) {
42+ const appIdValid = isValidUUID ( appIdInput . value ) ;
43+ const apiKeyValid = isValidApiKey ( apiKeyInput . value ) ;
44+ saveButton . disabled = ! ( appIdValid && apiKeyValid ) ; // Enable button only if both are valid
3145 }
32- }
3346
34- function toggleSaveButton ( ) {
35- const appIdValid = isValidUUID ( appIdInput . value ) ;
36- const apiKeyValid = isValidApiKey ( apiKeyInput . value ) ;
37- saveButton . disabled = ! ( appIdValid && apiKeyValid ) ; // Enable button only if both are valid
38- }
47+ appIdInput . addEventListener ( "input" , ( ) => {
48+ const isValid = isValidUUID ( appIdInput . value ) ;
49+ updateValidationIcon ( appIdInput , isValid ) ;
50+ toggleSaveButton ( ) ;
51+ } ) ;
3952
40- appIdInput . addEventListener ( ' input' , ( ) => {
41- const isValid = isValidUUID ( appIdInput . value ) ;
42- updateValidationIcon ( appIdInput , isValid ) ;
43- toggleSaveButton ( ) ;
44- } ) ;
53+ apiKeyInput . addEventListener ( " input" , ( ) => {
54+ const isValid = isValidApiKey ( apiKeyInput . value ) ;
55+ updateValidationIcon ( apiKeyInput , isValid ) ;
56+ toggleSaveButton ( ) ;
57+ } ) ;
4558
46- apiKeyInput . addEventListener ( 'input' , ( ) => {
47- const isValid = isValidApiKey ( apiKeyInput . value ) ;
48- updateValidationIcon ( apiKeyInput , isValid ) ;
59+ // Initial state on page load
4960 toggleSaveButton ( ) ;
50- } ) ;
51-
52- // Initial state on page load
53- toggleSaveButton ( ) ;
61+ }
5462} ) ;
0 commit comments