YouTube URL Cleaner

Clean YouTube URLs to only keep the video ID when Shift + Left Click is used and show a popup

  1. // ==UserScript==
  2. // @name YouTube URL Cleaner
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description Clean YouTube URLs to only keep the video ID when Shift + Left Click is used and show a popup
  6. // @author maanimis
  7. // @match *://*.youtube.com/*
  8. // @grant clipboardWrite
  9. // @run-at document-end
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const showPopup = (message) => {
  17. const popup = document.createElement('div');
  18. Object.assign(popup.style, {
  19. position: 'fixed',
  20. bottom: '20px',
  21. right: '20px',
  22. padding: '10px',
  23. background: 'black',
  24. color: 'white',
  25. borderRadius: '5px',
  26. boxShadow: '0px 0px 10px rgba(0,0,0,0.5)',
  27. zIndex: '1000',
  28. fontSize: '14px',
  29. fontFamily: 'Arial, sans-serif'
  30. });
  31. popup.textContent = message;
  32. document.body.appendChild(popup);
  33.  
  34. setTimeout(() => popup.remove(), 3000);
  35. };
  36.  
  37. const cleanUrl = () => {
  38. const urlMatch = window.location.href.match(/https?:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]+)/);
  39. if (!urlMatch) return;
  40.  
  41. const cleanUrl = `https://www.youtube.com/watch?v=${urlMatch[1]}`;
  42. navigator.clipboard.writeText(cleanUrl)
  43. .then(() => {
  44. console.log('Cleaned URL copied to clipboard:', cleanUrl);
  45. showPopup(`Copied: ${cleanUrl}`);
  46. })
  47. .catch(err => {
  48. console.error('Failed to copy URL:', err);
  49. showPopup('Failed to copy URL');
  50. });
  51. };
  52.  
  53. document.addEventListener('click', (event) => {
  54. if (event.shiftKey && event.button === 0) {
  55. cleanUrl();
  56. }
  57. });
  58. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址