@@ -6,86 +6,98 @@ document.addEventListener("DOMContentLoaded", function () {
6
6
} ;
7
7
8
8
const targetEye = document . getElementById ( "target-eye" ) ;
9
- let targetLabel = document . getElementById ( "target-label" ) ;
10
- let TargetEyeStyleObject = targetEye . style ;
9
+ const targetLabel = document . getElementById ( "target-label" ) ;
10
+ const TargetEyeStyleObject = targetEye . style ;
11
11
12
12
function OpenTarget ( ) {
13
- targetLabel . innerHTML = "" ;
13
+ targetLabel . textContent = "" ;
14
14
targetEye . style . display = "block" ;
15
15
targetEye . className = config . StandardEyeIcon ;
16
16
TargetEyeStyleObject . color = config . StandardColor ;
17
17
}
18
18
19
19
function CloseTarget ( ) {
20
- targetLabel . innerHTML = "" ;
20
+ targetLabel . textContent = "" ;
21
21
targetEye . style . display = "none" ;
22
22
}
23
23
24
+ function createTargetOption ( index , itemData ) {
25
+ if ( itemData !== null ) {
26
+ index = Number ( index ) + 1 ;
27
+ const targetOption = document . createElement ( "div" ) ;
28
+ targetOption . id = `target-option-${ index } ` ;
29
+ targetOption . style . marginBottom = "0.2vh" ;
30
+ targetOption . style . borderRadius = "0.15rem" ;
31
+ targetOption . style . padding = "0.45rem" ;
32
+ targetOption . style . background = "rgba(23, 23, 23, 40%)" ;
33
+ targetOption . style . color = config . StandardColor ;
34
+ const targetIcon = document . createElement ( "span" ) ;
35
+ targetIcon . id = `target-icon-${ index } ` ;
36
+ const icon = document . createElement ( "i" ) ;
37
+ icon . className = itemData . icon ;
38
+ targetIcon . appendChild ( icon ) ;
39
+ targetIcon . appendChild ( document . createTextNode ( " " ) ) ;
40
+ targetOption . appendChild ( targetIcon ) ;
41
+ targetOption . appendChild ( document . createTextNode ( itemData . label ) ) ;
42
+ targetLabel . appendChild ( targetOption ) ;
43
+ }
44
+ }
45
+
24
46
function FoundTarget ( item ) {
25
47
if ( item . data ) {
26
48
targetEye . className = item . data ;
27
49
}
28
50
TargetEyeStyleObject . color = config . SuccessColor ;
29
- targetLabel . innerHTML = "" ;
51
+ targetLabel . textContent = "" ;
30
52
for ( let [ index , itemData ] of Object . entries ( item . options ) ) {
31
- if ( itemData !== null ) {
32
- index = Number ( index ) + 1 ;
33
- targetLabel . innerHTML += `<div id="target-option-${ index } " style="margin-bottom: 0.2vh;
34
- border-radius: 0.15rem; padding: 0.45rem; background: rgba(23, 23, 23, 40%);
35
- color: ${ config . StandardColor } "><span id="target-icon-${ index } "><i class="${ itemData . icon } "></i> </span>${ itemData . label } </div>` ;
36
- }
53
+ createTargetOption ( index , itemData ) ;
37
54
}
38
55
}
39
56
40
57
function ValidTarget ( item ) {
41
- targetLabel . innerHTML = "" ;
58
+ targetLabel . textContent = "" ;
42
59
for ( let [ index , itemData ] of Object . entries ( item . data ) ) {
43
- if ( itemData !== null ) {
44
- index = Number ( index ) + 1 ;
45
- targetLabel . innerHTML += `<div id="target-option-${ index } " style="margin-bottom: 0.2vh;
46
- border-radius: 0.15rem; padding: 0.45rem; background: rgba(23, 23, 23, 40%);
47
- color: ${ config . StandardColor } "><span id="target-icon-${ index } "><i class="${ itemData . icon } "></i> </span>${ itemData . label } </div>` ;
48
- }
60
+ createTargetOption ( index , itemData ) ;
49
61
}
50
62
}
51
63
52
64
function LeftTarget ( ) {
53
- targetLabel . innerHTML = "" ;
65
+ targetLabel . textContent = "" ;
54
66
TargetEyeStyleObject . color = config . StandardColor ;
55
67
targetEye . className = config . StandardEyeIcon ;
56
68
}
57
69
58
70
function handleMouseDown ( event ) {
59
- let element = event . target ;
71
+ const element = event . target ; // use const instead of let
60
72
if ( element . id ) {
61
73
const split = element . id . split ( "-" ) ;
62
- if ( split [ 0 ] === "target" && split [ 1 ] !== "eye" && event . button == 0 ) {
74
+ if ( split [ 0 ] === "target" && split [ 1 ] !== "eye" && event . button === 0 ) {
63
75
fetch ( `https://${ GetParentResourceName ( ) } /selectTarget` , {
64
76
method : "POST" ,
65
77
headers : { "Content-Type" : "application/json; charset=UTF-8" } ,
66
78
body : JSON . stringify ( split [ 2 ] ) ,
67
- } ) ;
68
- targetLabel . innerHTML = "" ;
79
+ } ) . catch ( ( error ) => console . error ( "Error:" , error ) ) ;
80
+ targetLabel . textContent = "" ;
69
81
}
70
82
}
71
- if ( event . button == 2 ) {
83
+ if ( event . button === 2 ) {
72
84
LeftTarget ( ) ;
73
85
fetch ( `https://${ GetParentResourceName ( ) } /leftTarget` , {
74
86
method : "POST" ,
75
87
headers : { "Content-Type" : "application/json; charset=UTF-8" } ,
76
88
body : "" ,
77
- } ) ;
89
+ } ) . catch ( ( error ) => console . error ( "Error:" , error ) ) ;
78
90
}
79
91
}
80
92
81
93
function handleKeyDown ( event ) {
82
- if ( event . key == "Escape" || event . key == "Backspace" ) {
94
+ if ( event . key === "Escape" || event . key = == "Backspace" ) {
83
95
CloseTarget ( ) ;
84
96
fetch ( `https://${ GetParentResourceName ( ) } /closeTarget` , {
85
97
method : "POST" ,
86
98
headers : { "Content-Type" : "application/json; charset=UTF-8" } ,
87
99
body : "" ,
88
- } ) ;
100
+ } ) . catch ( ( error ) => console . error ( "Error:" , error ) ) ;
89
101
}
90
102
}
91
103
0 commit comments