Skip to content

Commit

Permalink
fix: incorrect feed if YouTube URL contained query string parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
teddy-gustiaux committed Nov 10, 2018
1 parent ab42c24 commit 224738b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
17 changes: 11 additions & 6 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class Utils {
const test = url.split(splitter)[1];
if (test) {
const id = test.split('/')[0];
if (id && typeof id !== 'undefined') channel = `${queryStringParameter}=${id}`;
if (id && typeof id !== 'undefined') {
// Remove query string parameters
const sanitizedId = id.split('?')[0];
channel = `${queryStringParameter}=${sanitizedId}`;
}
}
return channel || null;
}
Expand All @@ -61,15 +65,16 @@ class Utils {
* @returns {(string|null)} The URL of the channel RSS feed or `null` in case of error
*/
static buildChannelFeed(url) {
let channel = null;
let identifier = null;
if (url.split('channel/')[1]) {
channel = Utils.buildFeedIdentifier(url, 'channel/', 'channel_id');
identifier = Utils.buildFeedIdentifier(url, 'channel/', 'channel_id');
} else if (url.split('user/')[1]) {
channel = Utils.buildFeedIdentifier(url, 'user/', 'user');
identifier = Utils.buildFeedIdentifier(url, 'user/', 'user');
} else if (url.split('/').length === 4) {
channel = Utils.buildFeedIdentifier(url, 'youtube.com/', 'user');
identifier = Utils.buildFeedIdentifier(url, 'youtube.com/', 'user');
}
if (channel !== null) return FEED_BASE_URL + channel;
console.log(identifier)
if (identifier !== null) return FEED_BASE_URL + identifier;
return null;
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/content-script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/**
* List of selectors to retrieve the channel homepage address from the DOM.
* Supports both new and old YouTube layouts.
* @type {Array}
*/
const CHANNEL_URL_SELECTORS = [
'yt-formatted-string#owner-name :first-child',
'.yt-user-info :first-child',
];

/**
* Check if the provided input is nil (`null` or `undefined`)
* @param {*} input The input to test
Expand All @@ -22,6 +12,16 @@ function isNil(input) {
* @returns {(string|null)} The URL of the channel or `null` if not found
*/
function findChannelAddress() {
/**
* List of selectors to retrieve the channel homepage address from the DOM.
* Supports both new and old YouTube layouts.
* Must be defined in the function body to avoid redeclaration issues.
* @type {Array}
*/
const CHANNEL_URL_SELECTORS = [
'yt-formatted-string#owner-name :first-child',
'.yt-user-info :first-child',
];
let channelAddress = null;
// eslint-disable-next-line
for (let urlSelector of CHANNEL_URL_SELECTORS) {
Expand Down

0 comments on commit 224738b

Please sign in to comment.