mirror of
https://github.com/aureliendavid/rsspreview.git
synced 2025-08-22 19:28:39 +00:00
Improve YouTube feed detection
YouTube supports channels identified by both channel ID and channel name. For example, https://www.youtube.com/c/dslrvideoshooter and https://www.youtube.com/channel/UCMmA0XxraDP7ZVbv4eY3Omg are the same channel, but the former has a more human-friendly URL. This change allows the extension to detect the channel's RSS feed regardless of which URL is loaded using the canonical link provided on each channel page. This change is fully backward compatible.
This commit is contained in:
parent
4ca2e1cc3f
commit
acdf89e736
@ -379,10 +379,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findYouTubeFeeds() {
|
function findYouTubeFeeds() {
|
||||||
let match = document.URL.match(/channel\/([a-zA-Z0-9_-]+)/);
|
// YouTube's canonical channel URLs look like /channel/AlphaNumericID
|
||||||
if (match) {
|
// It also supports named channels of the form /c/MyChannelName
|
||||||
|
// Match on both of these to autodetect channel feeds on either URL
|
||||||
|
let idPattern = /channel\/(?<channelId>[a-zA-Z0-9_-]+)/;
|
||||||
|
let namePattern = /c\/[a-zA-Z0-9_-]+/;
|
||||||
|
let urlPattern = new RegExp(`${idPattern.source}|${namePattern.source}`);
|
||||||
|
if (document.URL.match(urlPattern)) {
|
||||||
let feeds = {};
|
let feeds = {};
|
||||||
let channelId = match[1];
|
let canonicalUrl = document.querySelector("link[rel='canonical']").href;
|
||||||
|
let channelId = canonicalUrl.match(idPattern).groups.channelId;
|
||||||
let url = `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`;
|
let url = `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`;
|
||||||
let title = document.title;
|
let title = document.title;
|
||||||
feeds[url] = title;
|
feeds[url] = title;
|
||||||
|
Loading…
Reference in New Issue
Block a user