YouTube Short Link Copier

Copy the short YouTube link directly when pressing Shift + S, and with timestamp when pressing Shift + C.

安装此脚本?
作者推荐脚本

您可能也喜欢Youtube polymer engine fixes

安装此脚本
  1. // ==UserScript==
  2. // @name YouTube Short Link Copier
  3. // @namespace https://greasyfork.org/en/scripts/474134-youtube-short-link-copier
  4. // @version 3.2
  5. // @description Copy the short YouTube link directly when pressing Shift + S, and with timestamp when pressing Shift + C.
  6. // @author passerbynwfow
  7. // @match https://www.youtube.com/*
  8. // @match https://music.youtube.com/*
  9. // @grant GM_setClipboard
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function getVideoIDFromQuery() {
  17. return new URLSearchParams(window.location.search).get("v");
  18. }
  19.  
  20. function getCurrentPlaybackTimeInSeconds() {
  21. const videoElem = document.querySelector('video');
  22. return videoElem ? Math.floor(videoElem.currentTime) : 0;
  23. }
  24.  
  25. document.addEventListener('keydown', function(e) {
  26. if (!e.shiftKey) return;
  27.  
  28. const host = window.location.host;
  29. const videoID = getVideoIDFromQuery();
  30. const currentSeconds = getCurrentPlaybackTimeInSeconds();
  31.  
  32. if (e.key === 'S') {
  33. if (host === 'www.youtube.com' && window.location.pathname.startsWith('/shorts/')) {
  34. GM_setClipboard(window.location.href);
  35. return;
  36. }
  37.  
  38. const baseLink = host === 'www.youtube.com' ? 'https://youtu.be/' : 'https://music.youtube.com/watch?v=';
  39. if (videoID) GM_setClipboard(`${baseLink}${videoID}`);
  40. } else if (e.key === 'C' && videoID) {
  41. const baseLink = host === 'www.youtube.com' ? 'https://youtu.be/' : 'https://music.youtube.com/watch?v=';
  42. GM_setClipboard(`${baseLink}${videoID}&t=${currentSeconds}`);
  43. }
  44. });
  45. })();