YouTube /embed/ forwarder

Forwards YouTube links to the youtube.com/embed/* page, so there's just the video in your window and nothing else.

< 脚本 YouTube /embed/ forwarder 的反馈

提问 / 留言

§
发布于:2025-08-05

Can you update the script please?

Vuccala作者
§
发布于:2025-08-07

Ok,I've updated it - it should work now.
YouTube changed how embeds work - they now can't be accessed without a referer (or something like that, I'm not sure) - so I added a redirect spoof so it gets its referer.
If you're on a dark theme like I am and the tab flashes white for a moment, sorry. I can't figure out how to get rid of that.

§
发布于:2025-08-08

Thank you for your fast reponse.

Also i just found out that you can embed a playlist like this:
Normal: https://www.youtube.com/watch?v=kPa7bsKwL-c&list=PLDIoUOhQQPlXr63I_vwF9GD8sAKh77dWU&index=2
Embed: https://www.youtube.com/embed/kPa7bsKwL-c?list=PLDIoUOhQQPlXr63I_vwF9GD8sAKh77dWU

Can you do that too?

§
发布于:2025-08-09

Nvm, i figured that out.

(function () {
const embedBaseUrl = 'https://www.youtube.com/embed/';

function getIds(u) {
const videoMatch = /(?:[?&]v=|\/(?:embed\/|v\/|shorts\/))([^&?/]+)/.exec(u);
const playlistMatch = /(?:[?&]list=)([^&?\/]+)/.exec(u);
if (videoMatch) {
if (playlistMatch) {
return { type: 'playlist', videoId: videoMatch[1], playlistId: playlistMatch[1] };
} else {
return { type: 'video', videoId: videoMatch[1] };
}
}
return null;
}

function createSpoofPage(embedUrl) {
const html = `

Redirecting to YouTube embed...

`;
const blob = new Blob([html], { type: 'text/html' });
return URL.createObjectURL(blob);
}

const url = window.location.href;
const ids = getIds(url);

if (ids) {
let embedUrl = '';
// embed URL with autoplay for both normal videos, playlist videos and shorts
if (ids.type === 'video') {
embedUrl = `${embedBaseUrl}${ids.videoId}?autoplay=1`;
} else if (ids.type === 'playlist') {
embedUrl = `${embedBaseUrl}${ids.videoId}?list=${ids.playlistId}&autoplay=1`;
}

if (embedUrl !== url) {
const spoofPage = createSpoofPage(embedUrl);
window.location.href = spoofPage;
}
}
})();

发布留言

登录以发布留言。