Skip to content

Instantly share code, notes, and snippets.

@laocoi
Forked from devAgam/resume.action.js
Created December 30, 2023 17:51
Show Gist options
  • Save laocoi/2bc81c36b0814907991cc65945b0e72a to your computer and use it in GitHub Desktop.
Save laocoi/2bc81c36b0814907991cc65945b0e72a to your computer and use it in GitHub Desktop.
Sample Function to Automate File Uploads through browser extensions
// This function does the following
// 1. fetches the PDF resume from the url provided
// 2. creates a file object with the resume data
// 3. triggers the change event on the file input element
// 4. the file input element gets the file object
// 5. the file object is uploaded to the website
async function handleResumeInput(remoteResumeURL) {
const designFile = await createFile(remoteResumeURL);
const input = document.querySelector('input[type="file"]');
const dt = new DataTransfer();
dt.items.add(designFile);
input.files = dt.files;
const event = new Event("change", {
bubbles: !0,
});
input.dispatchEvent(event);
}
async function createFile(url) {
let response = await fetch(url);
let data = await response.blob();
let metadata = {
type: "application/pdf",
};
return new File([data], "resume.pdf", metadata);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment