@@ -62,6 +62,50 @@ chrome.runtime
62
62
}
63
63
} ;
64
64
65
+ const downloadAdmitCard = ( ) => {
66
+ const newWindow = window . open (
67
+ "https://erp.iitkgp.ac.in/Acad/studentExamTimeView.jsp"
68
+ ) ;
69
+
70
+ if ( newWindow ) {
71
+ newWindow . addEventListener ( "load" , async ( ) => {
72
+ try {
73
+ // Fetch the PDF data from the URL
74
+ const response = await fetch (
75
+ "https://erp.iitkgp.ac.in/Acad/StudentAdmitCard.jsp"
76
+ ) ;
77
+
78
+ // Check if the response is successful
79
+ if ( response . ok ) {
80
+ // Get the PDF data as a Blob (binary large object)
81
+ const pdfBlob = await response . blob ( ) ;
82
+
83
+ // Create a temporary link to initiate the download
84
+ const downloadLink = document . createElement ( "a" ) ;
85
+ downloadLink . href =
86
+ window . URL . createObjectURL ( pdfBlob ) ;
87
+ downloadLink . download = "endsem_admitcard.pdf" ;
88
+ document . body . appendChild ( downloadLink ) ;
89
+ downloadLink . click ( ) ;
90
+ document . body . removeChild ( downloadLink ) ;
91
+
92
+ // Close the window after successfull download
93
+ newWindow . close ( ) ;
94
+ } else {
95
+ console . error (
96
+ "Failed to fetch the PDF:" ,
97
+ response . status
98
+ ) ;
99
+ }
100
+ } catch ( error ) {
101
+ console . error ( "Error occurred:" , error ) ;
102
+ }
103
+ } ) ;
104
+ } else {
105
+ console . error ( "Failed to open new window." ) ;
106
+ }
107
+ } ;
108
+
65
109
const solveCaptcha = async ( ) => {
66
110
captchaImage = document
67
111
. getElementById ( "myframe" )
@@ -182,7 +226,10 @@ chrome.runtime
182
226
. contentDocument . querySelectorAll (
183
227
'a[href="javascript:void(0)"]'
184
228
) ;
185
- if ( courseCounter == course . length ) return ;
229
+ if ( courseCounter == course . length ) {
230
+ downloadAdmitCard ( ) ;
231
+ return ;
232
+ }
186
233
course [ courseCounter ] . click ( ) ;
187
234
courseCounter ++ ;
188
235
0 commit comments