Skip to content

Instantly share code, notes, and snippets.

@amir-arad
Created September 13, 2022 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amir-arad/0f5cf673d6c03e0c8e341cd5be90fd9b to your computer and use it in GitHub Desktop.
Save amir-arad/0f5cf673d6c03e0c8e341cd5be90fd9b to your computer and use it in GitHub Desktop.
download pgotobucket gallery
/*
To use this:
1. paste the following code in chrome developer tools
*/
const { downloadZip } = await import(
"https://cdn.jsdelivr.net/npm/client-zip/index.js"
);
async function allImgs() {
const res = new Set();
const main = $("main");
const _$$ = $$;
const addCurrImgs = () => {
for (const img of _$$("img")) res.add(img.src);
};
main.scroll(0, 0);
for (const img of _$$("img")) res.add(img.src);
for (
let i = 0;
i < 1_000 && main.scrollTop + main.offsetHeight < main.scrollHeight;
i++
) {
console.log("scrolling");
main.scrollBy(0, 100);
for (const img of _$$("img")) res.add(img.src);
await new Promise((r) => setTimeout(r, 100));
}
console.log(`found ${res.size} images`);
return res;
}
async function* getFiles() {
for (const imgSrc of await allImgs()) {
const { pathname, origin } = new URL(imgSrc);
console.log("downloading");
yield await fetch(origin + pathname, {
headers: {
accept: "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9,he-IL;q=0.8,he;q=0.7",
"sec-ch-ua":
'"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
},
referrer: "https://next.photobucket.com/",
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "GET",
mode: "cors",
credentials: "omit",
});
await new Promise((res) => setTimeout(res, 10));
}
console.log("completed download");
}
async function dl(fileName) {
const blob = await downloadZip(getFiles()).blob();
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = fileName + ".zip";
link.click();
link.remove();
console.log("done");
}
/*
2. for each album you want to download:
2.1. open the album
2.2 scroll to the end of the album, to load all images
2.3 run the following line, change string to the name of the album
await dl('my album 123');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment