Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Convert YouTube Shorts and Copy to Clipboard
- // @namespace http://tampermonkey.net/
- // @version 2.3
- // @description Convert YouTube Shorts link (hotkey/menu)
- // @author Anon
- // @match *://www.youtube.com/shorts/*
- // @match *://www.youtube.com/watch?v=*
- // @grant GM_registerMenuCommand
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_setClipboard
- // ==/UserScript==
- // INSTRUCTIONS:
- // This script converts YouTube Shorts URLs into standard video URLs.
- // - Press Ctrl + Shift + Y (default hotkey) or click the button in the Tampermonkey menu to convert and copy the link.
- // - Converted links are copied to your clipboard and displayed as a popup.
- // - Use the Tampermonkey menu to set a custom hotkey.
- // - Enable "I Don't Use YT Shorts" mode from the menu to auto-redirect shorts links when visited.
- (function() {
- 'use strict';
- let menuCommands = [];
- function convertShortsLink() {
- let url = new URL(window.location.href);
- if (url.pathname.startsWith('/shorts/')) {
- let videoId = url.pathname.split('/')[2];
- let newUrl = `https://www.youtube.com/watch?v=${videoId}`;
- // Copy to clipboard
- GM_setClipboard(newUrl);
- // Show popup message
- showPopup(`Copied: ${newUrl}`);
- }
- }
- function showPopup(message) {
- let popup = document.createElement("div");
- popup.innerText = message;
- popup.style.position = "fixed";
- popup.style.bottom = "20px";
- popup.style.right = "20px";
- popup.style.background = "#222";
- popup.style.color = "#fff";
- popup.style.padding = "10px 15px";
- popup.style.borderRadius = "5px";
- popup.style.zIndex = "10000";
- popup.style.fontSize = "14px";
- popup.style.boxShadow = "0px 0px 10px rgba(0, 0, 0, 0.5)";
- popup.style.opacity = "1";
- popup.style.transition = "opacity 0.5s";
- document.body.appendChild(popup);
- setTimeout(() => {
- popup.style.opacity = "0";
- setTimeout(() => popup.remove(), 500);
- }, 2000);
- }
- function toggleAutoConvert() {
- let currentState = GM_getValue("autoConvert", false);
- let newState = !currentState;
- GM_setValue("autoConvert", newState);
- showPopup(`"I Don't Use YT Shorts" mode is now ${newState ? "ENABLED" : "DISABLED"}.`);
- registerMenu(); // Refresh menu
- }
- function setHotkey() {
- let currentHotkey = GM_getValue("hotkey", "Y");
- let newHotkey = prompt(
- `Enter a new hotkey letter (A-Z, 0-9):\n(Current hotkey: Ctrl + Shift + ${currentHotkey})\n\n` +
- `Your new hotkey will be: Ctrl + Shift + [Your Input]`,
- currentHotkey
- );
- if (newHotkey && /^[A-Z0-9]$/i.test(newHotkey)) {
- newHotkey = newHotkey.toUpperCase();
- GM_setValue("hotkey", newHotkey);
- registerMenu(); // Refresh menu with new hotkey
- }
- }
- function clearMenu() {
- while (menuCommands.length) {
- let cmd = menuCommands.pop();
- cmd.unregister();
- }
- }
- function registerMenu() {
- clearMenu();
- let hotkey = GM_getValue("hotkey", "Y");
- let autoConvert = GM_getValue("autoConvert", false);
- menuCommands.push(GM_registerMenuCommand("Convert & Copy YouTube Shorts Link (Ctrl + Shift + " + hotkey + ")", convertShortsLink));
- menuCommands.push(GM_registerMenuCommand("Set Custom Hotkey (Current: Ctrl + Shift + " + hotkey + ")", setHotkey));
- menuCommands.push(GM_registerMenuCommand(`Toggle "I Don't Use YT Shorts" Mode (Currently: ${autoConvert ? "ON" : "OFF"})`, toggleAutoConvert));
- }
- // Register menu commands
- registerMenu();
- // Listen for key presses
- document.addEventListener('keydown', function(event) {
- let hotkey = GM_getValue("hotkey", "Y");
- if (event.ctrlKey && event.shiftKey && event.key.toUpperCase() === hotkey) {
- convertShortsLink();
- }
- });
- // Auto-redirect if the user has enabled "I Don't Use YT Shorts" mode
- if (window.location.pathname.startsWith('/shorts/') && GM_getValue("autoConvert", false)) {
- let videoId = window.location.pathname.split('/')[2];
- window.location.href = `https://www.youtube.com/watch?v=${videoId}`;
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment