Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save subtleGradient/f57f4beef1a65989a543f5b4ddaf9cef to your computer and use it in GitHub Desktop.
Save subtleGradient/f57f4beef1a65989a543f5b4ddaf9cef to your computer and use it in GitHub Desktop.
javascript: (() => {
async function download(fileName, data) {
const content =
typeof data === "string" || data instanceof Blob
? data
: JSON.stringify(data);
const downloadURL = window.URL.createObjectURL(
new Blob([content], { type: "application/json" })
);
const anchor = document.createElement("a");
anchor.download = fileName;
anchor.href = downloadURL;
await new Promise(resolve => setTimeout(resolve, 0));
anchor.dispatchEvent(new MouseEvent("click"));
}
const getMD = () =>
[...document.querySelectorAll(`ytd-grid-video-renderer`)]
.map(item => ({
time: item.querySelector("ytd-thumbnail-overlay-time-status-renderer")
.innerText,
img: item.querySelector(`img.yt-img-shadow`).src,
title: item.querySelector(`a.ytd-grid-video-renderer`).title,
url: item.querySelector(`a.ytd-grid-video-renderer`).href
}))
.map(({ time, img, title, url }) =>
`- [[${title}]]\n - length:: ${time}\n - canonical url:: ${url}\n - thumbnail:: ![](${img})\n`.trim()
)
.join("\n");
const title = document.title
.replace(/^\(\d+\)\s+/, "")
.replace(` - YouTube`, "");
download(
`${title} YouTube Videos.md`,
`
- title:: [[${title}]]\n- canonical url:: ${
document.location.href
}\n- videos::\n${getMD().replace(/^/gm, " ")}
`.trim()
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment