2023-10-15 15:45:43 -05:00
|
|
|
// ==UserScript==
|
|
|
|
// @name YouTube2Piped
|
|
|
|
// @namespace YouTube
|
2023-10-27 02:47:13 -05:00
|
|
|
// @version 1.2.0
|
2023-10-15 15:45:43 -05:00
|
|
|
// @description Redirect YouTube to chosen Piped instance
|
|
|
|
// @author SinTan
|
|
|
|
// @match *://*.youtube.com/*
|
|
|
|
// @match *://youtu.be/*
|
|
|
|
// @icon https://raw.githubusercontent.com/TeamPiped/Piped/32e7ddaaff22f4a6c0d7f6359400323da7fefd69/public/img/icons/logo.svg
|
|
|
|
// @grant none
|
|
|
|
// @run-at document-start
|
2023-10-27 02:35:06 -05:00
|
|
|
// @license GPL-3.0-only
|
2023-10-15 15:45:43 -05:00
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
// Edit instance url here to go to any instance of choice
|
2023-10-20 00:09:26 -05:00
|
|
|
const instance = "https://piped.video"
|
2023-10-15 15:45:43 -05:00
|
|
|
|
|
|
|
const url = new URL(window.location.href.replace('/shorts/', '/watch?v='));
|
|
|
|
|
|
|
|
let id = url.searchParams.get('v');
|
|
|
|
let ts = url.searchParams.get('t');
|
|
|
|
if (id) {
|
|
|
|
let url_new = instance + '/watch?v=' + id;
|
|
|
|
if (ts) {
|
|
|
|
url_new = url_new + '&t=' + ts;
|
|
|
|
}
|
|
|
|
window.location.replace(url_new);
|
2023-10-27 02:35:06 -05:00
|
|
|
} else {
|
|
|
|
|
|
|
|
let pattern = /https:\/\/www\.youtube\.com\/channel\/([A-Za-z0-9\_\-]+).*/;
|
|
|
|
let channelId = pattern.exec(url)[1];
|
|
|
|
|
|
|
|
if (channelId) {
|
|
|
|
let url_new = instance + '/channel/' + channelId;
|
|
|
|
window.location.replace(url_new);
|
|
|
|
}
|
2023-10-15 15:45:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)();
|