feat: restore direct PDF download via background; drop printdoc
This commit is contained in:
+7
-15
@@ -150,25 +150,17 @@
|
||||
const btn = document.getElementById(BTN_ID);
|
||||
try {
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Opening...';
|
||||
btn.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Downloading...';
|
||||
const { header, courses } = await scrapeStudyLoad();
|
||||
const included = ISMIStools.filterStudyLoadCourses(courses);
|
||||
if (!included.length) throw new Error('No enrolled courses found.');
|
||||
const totalUnits = ISMIStools.sumUnits(included);
|
||||
const html = ISMIStools.buildStudyLoadHtml({ header, courses: included, totalUnits });
|
||||
const blob = new Blob([html], { type: 'text/html' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const win = window.open(url, '_blank');
|
||||
if (!win) {
|
||||
URL.revokeObjectURL(url);
|
||||
showToast('Popup blocked — allow popups for this site, then try again.', true);
|
||||
return;
|
||||
}
|
||||
// The blob document runs its own onload → window.print(). Never touch
|
||||
// win.document here: if the new tab navigates cross-origin, accessing it
|
||||
// throws "Permission denied".
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
showToast('Opened printable Study Load.');
|
||||
const res = await browser.runtime.sendMessage({
|
||||
type: 'generate-pdf',
|
||||
data: { header, courses: included, totalUnits }
|
||||
});
|
||||
if (!res || !res.ok) throw new Error((res && res.error) || 'PDF generation failed');
|
||||
showToast('PDF downloaded.');
|
||||
} catch (err) {
|
||||
showToast('Error: ' + ((err && err.message) || err), true);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user