Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-download for confirmations to docs #131

Open
hickeng opened this issue Mar 25, 2024 · 0 comments
Open

Add auto-download for confirmations to docs #131

hickeng opened this issue Mar 25, 2024 · 0 comments
Labels
enhancement New feature or request user experience User experience impacts

Comments

@hickeng
Copy link
Owner

hickeng commented Mar 25, 2024

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.

@hickeng hickeng added enhancement New feature or request user experience User experience impacts labels Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user experience User experience impacts
Projects
None yet
Development

No branches or pull requests

1 participant