YT Select Captions

Make YouTube captions selectable

  1. // ==UserScript==
  2. // @name YT Select Captions
  3. // @namespace https://greasyfork.org/users/901750-gooseob
  4. // @version 1.1
  5. // @description Make YouTube captions selectable
  6. // @author GooseOb
  7. // @license MIT
  8. // @match https://www.youtube.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  10. // ==/UserScript==
  11.  
  12. (() => {
  13. "use strict";
  14.  
  15. var until = (getItem, check, timeout = 1e4, interval = 20) =>
  16. new Promise((res, rej) => {
  17. let item = getItem();
  18. if (check(item)) return res(item);
  19. const limit = timeout / interval;
  20. let i = 0;
  21. const id = setInterval(() => {
  22. item = getItem();
  23. if (check(item)) {
  24. clearInterval(id);
  25. res(item);
  26. } else if (++i > limit) {
  27. clearInterval(id);
  28. rej(new Error(`Timeout: item ${getItem.name} wasn't found`));
  29. }
  30. }, interval);
  31. });
  32. var untilAppear = (getItem, msToWait) => until(getItem, Boolean, msToWait);
  33.  
  34. untilAppear(() =>
  35. document.getElementById("ytp-caption-window-container"),
  36. ).then((captionWindowCont) => {
  37. captionWindowCont.addEventListener(
  38. "mousedown",
  39. (e) => {
  40. e.stopPropagation();
  41. },
  42. { capture: true },
  43. );
  44. });
  45.  
  46. var style = document.createElement("style");
  47. style.textContent = `
  48. #ytp-caption-window-container {
  49. pointer-events: unset !important;
  50. }
  51. #ytp-caption-window-container > div {
  52. pointer-events: unset !important;
  53. user-select: text !important;
  54. -webkit-user-select: text !important;
  55. }
  56. .ytp-caption-segment {
  57. cursor: text !important;
  58. }
  59. `;
  60. document.head.appendChild(style);
  61. })();