Skip to content

Instantly share code, notes, and snippets.

@SamirTalwar
Last active April 30, 2023 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamirTalwar/6730180 to your computer and use it in GitHub Desktop.
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.
javascript: (function () {
const FeedQuerySelector = [
'link[rel~="alternate"][type="application/atom+xml"]',
'link[rel~="alternate"][type="application/rss+xml"]',
].join(", ");
const SubscriptionUrlPrefix = "https://www.newsblur.com/?url="; // change this for other services
const YouTubeChannel = /^https:\/\/www.youtube.com\/channel\/([A-Za-z0-9_\-]+)$/;
const YouTubePlaylist = /^https:\/\/www.youtube.com\/playlist\?list=([A-Za-z0-9_\-]+)$/;
const feedUrl = (function () {
if (
document.documentElement.nodeName === "feed" ||
document.body.childNodes[0].id == "webkit-xml-viewer-source-xml"
) {
return document.location.href;
} else if (YouTubeChannel.test(document.location.href)) {
const channelId = YouTubeChannel.exec(document.location.href)[1];
return `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`;
} else if (YouTubePlaylist.test(document.location.href)) {
const playlistId = YouTubePlaylist.exec(document.location.href)[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