Last active
January 13, 2025 21:50
-
-
Save SamirTalwar/6730180 to your computer and use it in GitHub Desktop.
"Subscribe" bookmarklet for NewsBlur. Copy and paste the code into the "Location" field of a new bookmark.
This file contains hidden or 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: (function () { | |
| /* change this for other services */ | |
| const SubscriptionUrlPrefix = "https://www.newsblur.com/?url="; | |
| const FeedQuerySelector = [ | |
| 'link[rel~="alternate"][type="application/atom+xml"]', | |
| 'link[rel~="alternate"][type="application/rss+xml"]', | |
| ].join(", "); | |
| const YouTubeChannel = /^https:\/\/www.youtube.com\/channel\/([A-Za-z0-9_\-]+)$/; | |
| const YouTubeChannelShort = /^https:\/\/www.youtube.com\/@([A-Za-z0-9_\-]+)$/; | |
| const YouTubePlaylist = /^https:\/\/www.youtube.com\/playlist\?list=([A-Za-z0-9_\-]+)$/; | |
| const feedUrl = (function () { | |
| let match; | |
| if ( | |
| document.documentElement.nodeName === "feed" || | |
| document.body.childNodes[0].id == "webkit-xml-viewer-source-xml" | |
| ) { | |
| return document.location.href; | |
| } else if ((match = YouTubeChannel.exec(document.location.href))) { | |
| const channelId = match[1]; | |
| return `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`; | |
| } else if ((match = YouTubeChannelShort.exec(document.location.href))) { | |
| const canonicalUrl = document.querySelector("link[rel=canonical]").href; | |
| match = YouTubeChannel.exec(canonicalUrl); | |
| const channelId = match[1]; | |
| return `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`; | |
| } else if ((match = YouTubePlaylist.exec(document.location.href))) { | |
| const playlistId = match[1]; | |
| return `https://www.youtube.com/feeds/videos.xml?playlist_id=${playlistId}`; | |
| } else { | |
| const element = document.querySelector(FeedQuerySelector); | |
| return element ? element.href : null; | |
| } | |
| })(); | |
| if (!feedUrl) { | |
| alert("No feed found."); | |
| return; | |
| } | |
| const url = SubscriptionUrlPrefix + encodeURIComponent(feedUrl); | |
| window.open(url, "_top"); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment