Pipelet: Open YouTube videos in Piped with a bookmarklet

Piped is a privacy-friendly, less bloated alternative YouTube frontend. To simplify opening YouTube videos in Piped, I made a bookmarklet that does two things:

  1. If the current tab is a video on YouTube, open the video on Piped
  2. If the current tab is any other page, open a prompt to paste a YouTube link (Useful for links and embedded videos)

Installation

Save the following link as a bookmark, or drag it to your bookmark toolbar:

Pipelet

Code:

var yt = ['www.youtube.com', 'youtube.com', 'youtu.be'];
var url = new URL(document.URL);

if (yt.includes(url.hostname)) {
    var path = url.pathname + url.search;
} else {
    url = new URL(prompt('Paste a YouTube URL here to open it in Piped:'));
    var path = url.pathname + url.search;
}
open('https://piped.video' + path)