Youtube Copy Comment

Copy comment from Youtube to clipboard. If there is a "See more" button here, click it.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            Youtube Copy Comment
// @name:vi         Sao Chép Bình Luận Youtube
// @namespace       https://lelinhtinh.github.io
// @description     Copy comment from Youtube to clipboard. If there is a "See more" button here, click it.
// @description:vi  Sao chép bình luận từ Youtube vào bộ nhớ đệm. Nếu có nút "Xem thêm" ở đây, nhấn vào nó.
// @version         1.0.1
// @icon            https://raw.githubusercontent.com/lelinhtinh/Userscript/master/yt_copy_comment/icon.png
// @author          lelinhtinh
// @oujs:author     baivong
// @license         MIT; https://baivong.mit-license.org/license.txt
// @match           https://www.youtube.com/live_chat
// @supportURL      https://github.com/lelinhtinh/Userscript/issues
// @run-at          document-idle
// @grant           none
// ==/UserScript==

document.addEventListener("click", (e) => {
  const mess = e.target.closest('span[dir="auto"]');
  if (!mess?.classList?.contains("yt-live-chat-text-message-renderer")) return;

  const commendText = mess.innerText;
  // console.log(commendText);
  if (!commendText) return;

  navigator.clipboard.writeText(commendText).then(
    () => {
      document.title = commendText;
      document.body.style.cursor = 'wait'
      setTimeout(() => {
        document.body.style.cursor = 'initial'
      }, 200);
    },
    () => {
      document.body.style.cursor = 'not-allowed'
      setTimeout(() => {
        document.body.style.cursor = 'initial'
      }, 200);
    },
  );
});