Follow the steps in https://gist.github.com/jeb5/da22862e469dea21e873acabb562f638
Last active
February 16, 2023 13:25
-
-
Save Yukaii/e8d6324522fbb277df4b2adb813f3739 to your computer and use it in GitHub Desktop.
YouTube Subscriptions to OPML RSS Feeds
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
let feeds = [...document.querySelectorAll('#main-link.channel-link')].map( | |
(e) => { | |
const channelHref = e.href; | |
const channelLink = window.location.origin + channelHref; | |
const name = e | |
.querySelector('.ytd-channel-name yt-formatted-string') | |
?.textContent.trim(); | |
const [, a, b] = e.href.match('/((?:user)|(?:channel))/(.*)$'); | |
const link = | |
'https://www.youtube.com/feeds/videos.xml?' + | |
(a === 'user' ? 'user=' : 'channel_id=') + | |
b; | |
return { | |
name, | |
link, | |
channelLink, | |
}; | |
}, | |
); | |
function copyToClipboard(text) { | |
const dummy = document.createElement('textarea'); | |
dummy.style.position = 'absolute'; | |
dummy.style.left = '-9999px'; | |
dummy.style.top = '-9999px'; | |
document.body.appendChild(dummy); | |
dummy.value = text; | |
dummy.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(dummy); | |
} | |
// generate OPML | |
const opml = `<?xml version="1.0" encoding="UTF-8"?> | |
<opml version="2.0"> | |
<head> | |
<title>My RSS Feeds</title> | |
</head> | |
<body> | |
${feeds | |
.map( | |
({ name, link, channelLink }) => ` | |
<outline text="${name.replace( | |
/"/g, | |
'"', | |
)}" type="rss" xmlUrl="${link}" htmlUrl="${channelLink}"/> | |
`, | |
) | |
.join('')} | |
</body> | |
</opml>`; | |
copyToClipboard(opml); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment