Added bookmarklets for auto download of files
This commit is contained in:
63
mrcooper_download_bookmarklet.js
Normal file
63
mrcooper_download_bookmarklet.js
Normal file
@@ -0,0 +1,63 @@
|
||||
javascript:(async function() {
|
||||
console.log(">>> MR COOPER DOWNLOADER STARTED");
|
||||
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
let capturedUrl = null;
|
||||
const originalWindowOpen = window.open;
|
||||
function enableInterceptor() {
|
||||
capturedUrl = null;
|
||||
window.open = function(url) {
|
||||
console.log(">>> Intercepted URL: " + url);
|
||||
capturedUrl = url;
|
||||
return { focus:()=>{}, close:()=>{} };
|
||||
};
|
||||
}
|
||||
function disableInterceptor() { window.open = originalWindowOpen; }
|
||||
const dateDivs = Array.from(document.querySelectorAll(".statement-date-no-type"));
|
||||
if (dateDivs.length === 0) {
|
||||
alert("No statements found! Make sure you are on the Statements page.");
|
||||
return;
|
||||
}
|
||||
let downloadCount = 0;
|
||||
for (const dateDiv of dateDivs) {
|
||||
if (dateDiv.innerText.trim() === "DATE") continue;
|
||||
const row = dateDiv.closest(".row.collapse");
|
||||
const btn = row.querySelector(".view-statement-button");
|
||||
if (!btn) continue;
|
||||
const rawDate = dateDiv.innerText.trim();
|
||||
const d = new Date(rawDate);
|
||||
if (isNaN(d.getTime())) continue;
|
||||
const yyyy = d.getFullYear();
|
||||
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const dd = String(d.getDate()).padStart(2, '0');
|
||||
const cleanDate = yyyy + "-" + mm + "-" + dd;
|
||||
const filename = "Mr Cooper - E 2nd - " + cleanDate + ".pdf";
|
||||
enableInterceptor();
|
||||
btn.click();
|
||||
let attempts = 0;
|
||||
while (capturedUrl === null && attempts < 20) {
|
||||
await wait(200);
|
||||
attempts++;
|
||||
}
|
||||
disableInterceptor();
|
||||
if (capturedUrl) {
|
||||
try {
|
||||
const response = await fetch(capturedUrl);
|
||||
const blob = await response.blob();
|
||||
const blobUrl = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = blobUrl;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
document.body.removeChild(a);
|
||||
downloadCount++;
|
||||
} catch (e) {
|
||||
console.error("Fetch failed", e);
|
||||
}
|
||||
}
|
||||
await wait(1500);
|
||||
}
|
||||
alert("Done! Downloaded " + downloadCount + " files.");
|
||||
})();
|
||||
Reference in New Issue
Block a user