Guest User

Tampermonkey Script - Convert YouTube Shorts and Copy to Clipboard

a guest
Mar 19th, 2025
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name Convert YouTube Shorts and Copy to Clipboard
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.3
  5. // @description Convert YouTube Shorts link (hotkey/menu)
  6. // @author Anon
  7. // @match *://www.youtube.com/shorts/*
  8. // @match *://www.youtube.com/watch?v=*
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_setClipboard
  13. // ==/UserScript==
  14.  
  15. // INSTRUCTIONS:
  16. // This script converts YouTube Shorts URLs into standard video URLs.
  17. // - Press Ctrl + Shift + Y (default hotkey) or click the button in the Tampermonkey menu to convert and copy the link.
  18. // - Converted links are copied to your clipboard and displayed as a popup.
  19. // - Use the Tampermonkey menu to set a custom hotkey.
  20. // - Enable "I Don't Use YT Shorts" mode from the menu to auto-redirect shorts links when visited.
  21.  
  22. (function() {
  23. 'use strict';
  24.  
  25. let menuCommands = [];
  26.  
  27. function convertShortsLink() {
  28. let url = new URL(window.location.href);
  29.  
  30. if (url.pathname.startsWith('/shorts/')) {
  31. let videoId = url.pathname.split('/')[2];
  32. let newUrl = `https://www.youtube.com/watch?v=${videoId}`;
  33.  
  34. // Copy to clipboard
  35. GM_setClipboard(newUrl);
  36.  
  37. // Show popup message
  38. showPopup(`Copied: ${newUrl}`);
  39. }
  40. }
  41.  
  42. function showPopup(message) {
  43. let popup = document.createElement("div");
  44. popup.innerText = message;
  45. popup.style.position = "fixed";
  46. popup.style.bottom = "20px";
  47. popup.style.right = "20px";
  48. popup.style.background = "#222";
  49. popup.style.color = "#fff";
  50. popup.style.padding = "10px 15px";
  51. popup.style.borderRadius = "5px";
  52. popup.style.zIndex = "10000";
  53. popup.style.fontSize = "14px";
  54. popup.style.boxShadow = "0px 0px 10px rgba(0, 0, 0, 0.5)";
  55. popup.style.opacity = "1";
  56. popup.style.transition = "opacity 0.5s";
  57.  
  58. document.body.appendChild(popup);
  59.  
  60. setTimeout(() => {
  61. popup.style.opacity = "0";
  62. setTimeout(() => popup.remove(), 500);
  63. }, 2000);
  64. }
  65.  
  66. function toggleAutoConvert() {
  67. let currentState = GM_getValue("autoConvert", false);
  68. let newState = !currentState;
  69. GM_setValue("autoConvert", newState);
  70. showPopup(`"I Don't Use YT Shorts" mode is now ${newState ? "ENABLED" : "DISABLED"}.`);
  71. registerMenu(); // Refresh menu
  72. }
  73.  
  74. function setHotkey() {
  75. let currentHotkey = GM_getValue("hotkey", "Y");
  76. let newHotkey = prompt(
  77. `Enter a new hotkey letter (A-Z, 0-9):\n(Current hotkey: Ctrl + Shift + ${currentHotkey})\n\n` +
  78. `Your new hotkey will be: Ctrl + Shift + [Your Input]`,
  79. currentHotkey
  80. );
  81.  
  82. if (newHotkey && /^[A-Z0-9]$/i.test(newHotkey)) {
  83. newHotkey = newHotkey.toUpperCase();
  84. GM_setValue("hotkey", newHotkey);
  85. registerMenu(); // Refresh menu with new hotkey
  86. }
  87. }
  88.  
  89. function clearMenu() {
  90. while (menuCommands.length) {
  91. let cmd = menuCommands.pop();
  92. cmd.unregister();
  93. }
  94. }
  95.  
  96. function registerMenu() {
  97. clearMenu();
  98. let hotkey = GM_getValue("hotkey", "Y");
  99. let autoConvert = GM_getValue("autoConvert", false);
  100.  
  101. menuCommands.push(GM_registerMenuCommand("Convert & Copy YouTube Shorts Link (Ctrl + Shift + " + hotkey + ")", convertShortsLink));
  102. menuCommands.push(GM_registerMenuCommand("Set Custom Hotkey (Current: Ctrl + Shift + " + hotkey + ")", setHotkey));
  103. menuCommands.push(GM_registerMenuCommand(`Toggle "I Don't Use YT Shorts" Mode (Currently: ${autoConvert ? "ON" : "OFF"})`, toggleAutoConvert));
  104. }
  105.  
  106. // Register menu commands
  107. registerMenu();
  108.  
  109. // Listen for key presses
  110. document.addEventListener('keydown', function(event) {
  111. let hotkey = GM_getValue("hotkey", "Y");
  112.  
  113. if (event.ctrlKey && event.shiftKey && event.key.toUpperCase() === hotkey) {
  114. convertShortsLink();
  115. }
  116. });
  117.  
  118. // Auto-redirect if the user has enabled "I Don't Use YT Shorts" mode
  119. if (window.location.pathname.startsWith('/shorts/') && GM_getValue("autoConvert", false)) {
  120. let videoId = window.location.pathname.split('/')[2];
  121. window.location.href = `https://www.youtube.com/watch?v=${videoId}`;
  122. }
  123. })();
  124.  
Advertisement
Add Comment
Please, Sign In to add comment