Greasy Fork is available in English.

YouTube URL Converter

Convert YouTube Shorts URL to regular YouTube video URL.

Fra 18.10.2023. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name YouTube URL Converter
  3. // @name:zh-TW YouTube URL 轉換器
  4. // @name:ja YouTube URL コンバーター
  5. // @name:zh-CN YouTube URL 转换器
  6. // @namespace http://tampermonkey.net/
  7. // @version 1.0
  8. // @description Convert YouTube Shorts URL to regular YouTube video URL.
  9. // @description:zh-TW 將 YouTube Shorts 網址轉換為常規的 YouTube 影片網址。
  10. // @description:ja YouTube Shorts URLを通常のYouTubeビデオURLに変換します。
  11. // @description:zh-CN 将 YouTube Shorts 网址转换为常规的 YouTube 视频网址。
  12. // @author 鮪魚大師
  13. // @match https://www.youtube.com/*
  14. // @grant none
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21. let convertButton;
  22.  
  23. function createConvertButton() {
  24. if (!convertButton) {
  25. convertButton = document.createElement('button');
  26. convertButton.textContent = 'Shorts網址轉換';
  27. convertButton.style.position = 'fixed';
  28. convertButton.style.top = '150px';
  29. convertButton.style.right = '10px';
  30. convertButton.style.zIndex = '9999';
  31. convertButton.style.backgroundColor = '#FF0000';
  32. convertButton.style.color = '#FFFFFF';
  33. convertButton.style.fontSize = '24px';
  34. convertButton.style.padding = '10px 20px';
  35. convertButton.style.border = 'none';
  36. convertButton.style.borderRadius = '5px';
  37. convertButton.title = '將Shorts網址轉換成一般影片網址';
  38. document.body.appendChild(convertButton);
  39.  
  40. convertButton.addEventListener('click', convertURL);
  41. }
  42. }
  43.  
  44. function convertURL() {
  45. const currentURL = window.location.href;
  46. if (currentURL.includes("youtube.com/shorts/")) {
  47. const match = currentURL.match(/https:\/\/www\.youtube\.com\/shorts\/([A-Za-z0-9_-]+)/);
  48. if (match) {
  49. const videoID = match[1];
  50. const videoURL = `https://www.youtube.com/watch?v=${videoID}`;
  51. window.location.href = videoURL;
  52. }
  53. }
  54. }
  55.  
  56. function removeConvertButton() {
  57. if (convertButton) {
  58. convertButton.remove();
  59. convertButton = null;
  60. }
  61. }
  62.  
  63. function checkAndCreateButton() {
  64. if (window.location.href.includes("youtube.com/shorts/")) {
  65. createConvertButton();
  66. } else {
  67. removeConvertButton();
  68. }
  69. }
  70.  
  71. checkAndCreateButton();
  72.  
  73. window.addEventListener('popstate', checkAndCreateButton);
  74.  
  75. const observer = new MutationObserver(function(mutationsList, observer) {
  76. for (const mutation of mutationsList) {
  77. if (mutation.type === 'childList') {
  78. checkAndCreateButton();
  79. }
  80. }
  81. });
  82.  
  83. observer.observe(document.documentElement, { childList: true, subtree: true });
  84. })();