[YouTube] Remove share dialog

Copies link without oepning share dialog

Tính đến 05-11-2022. Xem phiên bản mới nhất.

  1. // ==UserScript==
  2. // @name [YouTube] Remove share dialog
  3. // @version 0.3
  4. // @description Copies link without oepning share dialog
  5. // @author SL1900
  6. // @match *://www.youtube.com/*
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  8. // @license MIT
  9. // @namespace http://tampermonkey.net/
  10. // ==/UserScript==
  11.  
  12. (async function() {
  13. 'use strict';
  14.  
  15. const $ = document.querySelector.bind(document);
  16. const $$ = document.querySelectorAll.bind(document);
  17.  
  18. const sleep = (time) => new Promise(resolve => setTimeout(resolve,time));
  19.  
  20. while(true)
  21. {
  22. //Check for button to place over and if my button was is already placed
  23. let button = $("ytd-segmented-like-dislike-button-renderer");
  24. let replace = $("#sl_share_replace");
  25. if(!button || replace){
  26. //Wait to prevent page from freezing
  27. await sleep(200);
  28. continue;
  29. }
  30.  
  31.  
  32. button = button.nextSibling;
  33. button.style.position = "relative";
  34. button.style.userSelect = "none";
  35.  
  36. //Style for blink animation
  37. let style = document.createElement("style");
  38. style.innerHTML += `
  39. #sl_share_replace{
  40. position: absolute;
  41. top: 0;
  42. bottom: 0;
  43. left: 0;
  44. right: 0;
  45. cursor: pointer;
  46. }
  47. .blinknode
  48. {
  49. animation: blink 0.7s ease;
  50. border-radius: 18px;
  51. }
  52. @keyframes blink{
  53. 0% { background-color: #000000}
  54. 25%{ background-color: #bbbbbb}
  55. 50% { background-color: #000000}
  56. 75%{ background-color: #bbbbbb}
  57. 100% { background-color: #000000}
  58. }`;
  59. button.appendChild(style);
  60.  
  61. //Getting element with "Share" text to change it to "Copied" on click
  62. let textnode = button.querySelector(".cbox .yt-core-attributed-string[role=text]");
  63.  
  64. //Creating my button
  65. let my_btn = document.createElement("div");
  66. my_btn.id = "sl_share_replace";
  67. let appended_btn = button.appendChild(my_btn);
  68.  
  69. //On click behaviour
  70. appended_btn.addEventListener("click",(event)=>{
  71. //Get video id
  72. let link = window.location.href;
  73. let video_id = link.match(/(?<=\?v=).+?(?=(&|$))/ig);
  74. let final_link = `https://youtu.be/${video_id}`;
  75.  
  76. //Get video current time
  77. let time = Math.floor($(".video-stream").currentTime);
  78.  
  79. //Add timestamp to link if Shift key is pressed
  80. if(event.shiftKey) final_link += "?t=" + time;
  81.  
  82. //Copy link to clipboard
  83. navigator.clipboard.writeText(final_link);
  84. console.log(`[Add share button] Link copied to clipboard. [${final_link}]`);
  85.  
  86. //Change "Share" to "Copied" and add "blinknode" class to start animation
  87. textnode.innerHTML = "Copied";
  88. button.classList.add("blinknode");
  89.  
  90. //Change "Copied" back to "Share" and remove class to be able to start animation again
  91. setTimeout(()=>{
  92. textnode.innerHTML = "Share";
  93. button.classList.remove("blinknode");
  94. },1000);
  95. });
  96.  
  97. //Wait to prevent page from freezing
  98. await sleep(200);
  99. }
  100. })();