Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,44 @@
setThemeFromPreference();
const params = new URLSearchParams(window.location.search.substring(1));
if (params.has('v')) {
const url = new URL(params.get('v'));
const urlParams = new URLSearchParams(url.search.substring(1));
// See https://developers.google.com/youtube/player_parameters for supported parameters
const outputParams = new URLSearchParams();
try {
let rawUrl = params.get('v');

if (urlParams.has('t')) {
outputParams.append('start', urlParams.get('t'));
}
// URL parsing will fail if there is no protocol
if (!rawUrl.split(".")[0].includes("://")) {
rawUrl = "https://" + rawUrl;
}

const url = new URL(rawUrl);
const urlParams = new URLSearchParams(url.search.substring(1));
// See https://developers.google.com/youtube/player_parameters for supported parameters
const outputParams = new URLSearchParams();

if (url.hostname == 'youtube.com' || url.hostname.endsWith('.youtube.com')) {
if (urlParams.has('list')) {
outputParams.append('listType', 'playlist');
outputParams.append('list', urlParams.get('list'));
if (urlParams.has('t')) {
outputParams.append('start', urlParams.get('t'));
}

let id = '';
if (urlParams.has('v')) {
id = urlParams.get('v');
if (url.hostname == 'youtube.com' || url.hostname.endsWith('.youtube.com')) {
if (urlParams.has('list')) {
outputParams.append('listType', 'playlist');
outputParams.append('list', urlParams.get('list'));
}

let id = '';
if (urlParams.has('v')) {
id = urlParams.get('v');
}
purify(id, outputParams);
} else if (url.hostname == 'youtu.be') {
const id = url.pathname.substring(1);
purify(id, outputParams);
} else {
throw "Unknown hostname";
}
purify(id, outputParams);
} else if (url.hostname == 'youtu.be') {
const id = url.pathname.substring(1);
purify(id, outputParams);
} catch (e) {
setTimeout(() => alert("Failed to parse URL. Please make sure the URL is a valid YouTube video or playlist."), 500);
// Also show it in the console
throw e;
}
}
}
Expand Down