Skip to content

Commit b489f26

Browse files
committed
feat: auto download admit card
1 parent 4297fa2 commit b489f26

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

extension-src/chrome/js/feedback.js

+48-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,50 @@ chrome.runtime
6262
}
6363
};
6464

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+
65109
const solveCaptcha = async () => {
66110
captchaImage = document
67111
.getElementById("myframe")
@@ -182,7 +226,10 @@ chrome.runtime
182226
.contentDocument.querySelectorAll(
183227
'a[href="javascript:void(0)"]'
184228
);
185-
if (courseCounter == course.length) return;
229+
if (courseCounter == course.length) {
230+
downloadAdmitCard();
231+
return;
232+
}
186233
course[courseCounter].click();
187234
courseCounter++;
188235

extension-src/firefox/js/feedback.js

+47-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,49 @@ browser.runtime
6161
submitButton.click();
6262
}
6363
};
64+
const downloadAdmitCard = () => {
65+
const newWindow = window.open(
66+
"https://erp.iitkgp.ac.in/Acad/studentExamTimeView.jsp"
67+
);
68+
69+
if (newWindow) {
70+
newWindow.addEventListener("load", async () => {
71+
try {
72+
// Fetch the PDF data from the URL
73+
const response = await fetch(
74+
"https://erp.iitkgp.ac.in/Acad/StudentAdmitCard.jsp"
75+
);
76+
77+
// Check if the response is successful
78+
if (response.ok) {
79+
// Get the PDF data as a Blob (binary large object)
80+
const pdfBlob = await response.blob();
81+
82+
// Create a temporary link to initiate the download
83+
const downloadLink = document.createElement("a");
84+
downloadLink.href =
85+
window.URL.createObjectURL(pdfBlob);
86+
downloadLink.download = "endsem_admitcard.pdf";
87+
document.body.appendChild(downloadLink);
88+
downloadLink.click();
89+
document.body.removeChild(downloadLink);
90+
91+
// Close the window after successfull download
92+
newWindow.close();
93+
} else {
94+
console.error(
95+
"Failed to fetch the PDF:",
96+
response.status
97+
);
98+
}
99+
} catch (error) {
100+
console.error("Error occurred:", error);
101+
}
102+
});
103+
} else {
104+
console.error("Failed to open new window.");
105+
}
106+
};
64107

65108
const solveCaptcha = async () => {
66109
captchaImage = document
@@ -182,7 +225,10 @@ browser.runtime
182225
.contentDocument.querySelectorAll(
183226
'a[href="javascript:void(0)"]'
184227
);
185-
if (courseCounter == course.length) return;
228+
if (courseCounter == course.length) {
229+
downloadAdmitCard();
230+
return;
231+
}
186232
course[courseCounter].click();
187233
courseCounter++;
188234

0 commit comments

Comments
 (0)