Skip to content

Instantly share code, notes, and snippets.

@caltuntas
Created September 12, 2026 07:18
Show Gist options
  • Select an option

  • Save caltuntas/0902dd82d8c5470eb0e512af56a82cc7 to your computer and use it in GitHub Desktop.

Select an option

Save caltuntas/0902dd82d8c5470eb0e512af56a82cc7 to your computer and use it in GitHub Desktop.
so-saved-questions
(async () => {
const results = new Map();
async function fetchPage(url) {
const response = await fetch(url, {
credentials: "include"
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${url}`);
}
return new DOMParser().parseFromString(
await response.text(),
"text/html"
);
}
function extract(doc) {
doc.querySelectorAll(".s-post-summary").forEach(post => {
const id = post.dataset.postId;
const title = post.querySelector(
".s-post-summary--content-title a"
)?.textContent.trim() || "";
const link = post.querySelector(
".s-post-summary--content-title a"
)?.href || "";
const category = post.querySelector(
".js-saved-in"
)?.textContent.trim() || "";
if (id && link) {
results.set(id, {
id,
title,
category,
link
});
}
});
}
function getNextUrl(doc) {
const next = [...doc.querySelectorAll("a")].find(
a => a.textContent.trim() === "Next"
);
return next?.href || null;
}
let url = location.href;
let page = 1;
while (url) {
console.log(`Fetching page ${page}...`);
const doc = await fetchPage(url);
extract(doc);
console.log(`Collected ${results.size} saves so far`);
url = getNextUrl(doc);
page++;
if (url) {
await new Promise(resolve => setTimeout(resolve, 500));
}
}
const output = [...results.values()];
// Make the complete result available globally.
window.stackoverflowSaves = output;
// Download complete JSON.
const blob = new Blob(
[JSON.stringify(output, null, 2)],
{ type: "application/json" }
);
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "stackoverflow-saves.json";
a.click();
console.log(`DONE: ${output.length} saved posts`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment