Greasy Fork

Greasy Fork is available in English.

YouTube UnShortner

Turns YouTube Shorts into normal YouTube videos

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          YouTube UnShortner
// @description   Turns YouTube Shorts into normal YouTube videos
// @icon          https://www.google.com/s2/favicons?domain=www.youtube.com
// @version       1.0.0 (20/08/2023)
// @author        gt10i
// @homepage      https://github.com/gt10i
// @namespace     Violentmonkey Scripts
// @license       MIT
// @grant         none
// @run-at        document-start
// @match         https://www.youtube.com/*
// @match         https://www.youtu.be/*
// @match         https://m.youtube.com/*
// ==/UserScript==

if (test(location.href)) {
  updateUrl()
}

let previousUrl = '';
let observer = new MutationObserver(function(mutations) {
  if (location.href !== previousUrl) {
      if (test(location.href)) {
        updateUrl()
      }
      previousUrl = location.href;
      console.log(`URL changed to ${location.href}`);
    }
});

observer.observe(document, { childList: true, subtree: true })

function test(url){
  var isYouTubeShortUrl = !!url.match(/^(|http(s?):\/\/)(|www.)(youtube.com|youtu.be)\/shorts(\/.*|$)/gim);

  return isYouTubeShortUrl;
}

function updateUrl(){
    window.location.replace("https://youtube.com/watch?v=" + videoIdFromUrl());
}

function videoIdFromUrl(){
    const videoIdExtractRegex = /(youtube.com|youtu.be)\/shorts\/([0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]*)/gi;
    const youtubeRegex = new RegExp(videoIdExtractRegex);
    const regexResult = youtubeRegex.exec(window.location.href);
    const videoId = regexResult[2];

    return videoId;
}