YouTube - Open Uploaded Videos Playlist

YouTube - Open Uploaded Videos Playlist.

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube - Open Uploaded Videos Playlist
// @description  YouTube - Open Uploaded Videos Playlist.
// @version      0.5
// @author       to
// @namespace    https://github.com/to
// @license      MIT
//
//
// @noframes
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// 
// @grant        GM_registerMenuCommand
// @grant        GM_openInTab
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        unsafeWindow
// ==/UserScript==

// 新しいタブで開くか?(保存データタブで書き換え)
const OPEN_IN_TAB = GM_getValue('openInTab', null);
if (OPEN_IN_TAB == null)
	GM_setValue('openInTab', false);

GM_registerMenuCommand('Open Uploaded Videos Playlist', () => {
	let channelId;

	// 個別ページか?
	if (unsafeWindow.ytInitialPlayerResponse) {
		channelId = unsafeWindow.ytInitialPlayerResponse.videoDetails.channelId;
	} else {
		try {
			channelId = document.querySelector('link[rel="canonical"]').href.match(/channel\/(.+)/)[1];
		} catch {
			alert('This is not the intended page.');
			return;
		}
	}

	// 新しいタブで開くか?
	let url = 'https://www.youtube.com/playlist?list=UU' + channelId.slice(2)
	OPEN_IN_TAB ?
		GM_openInTab(url) :
		location.href = url;
});

// 個別ページか?
if (unsafeWindow.ytInitialPlayerResponse) {
	// 開いている動画よりも新しいものへ向かって連続再生する
	GM_registerMenuCommand('Open Newer Videos Playlist', () => {
		location.href = `https://www.youtube.com/watch?v=${unsafeWindow.ytInitialPlayerResponse.videoDetails.videoId}&list=UL01234567890`;
	});
}