Last active
June 4, 2020 07:12
-
-
Save subtleGradient/f57f4beef1a65989a543f5b4ddaf9cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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