Skip to content

Add auto-download for confirmations to docs #131

@hickeng

Description

@hickeng

Steve has provided a script that can be run via browser devtools that will auto-download your stockplan confirmations.

Most browsers have devtools bound to F12 but are also available via menus.
Go to the etrade stock confirmations page, select a year, paste in the following into the dev tools console tab.

// Function to download a file given a URL
const downloadFile = async (url) => {
  try {
    const response = await fetch(url);
    const blob = await response.blob();
    const fileName = url.substring(url.lastIndexOf('/') + 1).replace(/\?.*/, ''); // Extract filename from URL and remove query string
    const a = document.createElement('a');
    a.href = window.URL.createObjectURL(blob);
    a.download = fileName.endsWith('.pdf') ? fileName : `${fileName}.pdf`; // Ensure file extension is ".pdf"
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    await new Promise((resolve) => setTimeout(resolve, 1000)); // Delay for 1 second
  } catch (error) {
    console.error('Error downloading file:', error);
  }
};

// Function to check if a link is a PDF download link
const isPDFLink = (link) => {
  return link.href && link.href.includes('/webapisp/stockplan/pdf/get');
};

// Iterate through all links on the page and download PDF files
document.querySelectorAll('a').forEach((link) => {
  if (isPDFLink(link)) {
    downloadFile(link.href);
  }
});

I've not tried this myself yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions