File tree 1 file changed +22
-3
lines changed
1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 32
32
}
33
33
</ style >
34
34
< script >
35
- async function fetchEvents ( ) {
36
- const username = document . getElementById ( "username" ) . value ;
35
+ async function fetchEvents ( username ) {
37
36
if ( ! username ) {
38
37
alert ( "Please enter a username" ) ;
39
38
return ;
72
71
</div>
73
72
` ;
74
73
}
74
+
75
+ let username = / \? u s e r n a m e = ( [ ^ & ] + ) / . exec ( window . location . search ) [ 1 ] ;
76
+ if ( username ) {
77
+ fetchEvents ( username ) ;
78
+ setTimeout ( ( ) => {
79
+ document . getElementById ( "username" ) . value = username ;
80
+ } , 1000 ) ;
81
+ }
82
+
83
+ function redirect ( ) {
84
+ const username = document . getElementById ( "username" ) . value ;
85
+
86
+ if ( ! username ) {
87
+ alert ( "Please enter a username" ) ;
88
+ return ;
89
+ }
90
+
91
+ window . location . href = `/?username=${ username } ` ;
92
+ }
93
+
75
94
</ script >
76
95
</ head >
77
96
< body >
78
97
< h1 > Enter GitHub Username to Fetch Events</ h1 >
79
98
< input type ="text " id ="username " placeholder ="Enter GitHub username " />
80
- < button onclick ="fetchEvents () "> Fetch Events</ button >
99
+ < button onclick ="redirect () "> Fetch Events</ button >
81
100
82
101
< div id ="result " style ="margin-top: 20px "> </ div >
83
102
</ body >
You can’t perform that action at this time.
0 commit comments