YouTube shorts redirect

YouTube shorts redirect / YouTube shorts redirect

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTube shorts redirect
// @namespace    http://tampermonkey.net/
// @version      0.3
// @author       Fuim
// @match        *://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// @run-at       document-start
// @license      GNU GPLv2
// @description YouTube shorts redirect / YouTube shorts redirect
// ==/UserScript==

(function () {
	'use strict';
	function redirect() {
		if (location.pathname.startsWith("/shorts")) {
			// 0     1       2
			//   /shorts/abcde123456
			const videoId = location.pathname.split("/")[2];
			const newUrl = "https://www.youtube.com/watch?v=" + videoId;
			window.location.replace(newUrl);
		}
	}

	// Run it normally once in case a youtube shorts url was opened directly
	redirect();

	// Use this event so it'll work when navigating inside of youtube.
	// Otherwise, people have to refresh the page for it to work.
	// Some other events that might work? yt-page-data-updated, yt-page-type-changed, yt-navigate-finish
	document.addEventListener("yt-navigate-start", redirect);

})();