Facebook Copy Comment

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name            Facebook Copy Comment
// @name:vi         Sao Chép Bình Luận Facebook
// @namespace       https://lelinhtinh.github.io
// @description     Copy comment from Facebook to clipboard. If there is a "See more" button here, click it.
// @description:vi  Sao chép bình luận từ Facebook 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://i.imgur.com/F8ai0jB.png
// @author          lelinhtinh
// @oujs:author     baivong
// @license         MIT; https://baivong.mit-license.org/license.txt
// @match           https://facebook.com/*
// @match           https://*.facebook.com/*
// @noframes
// @supportURL      https://github.com/lelinhtinh/Userscript/issues
// @run-at          document-idle
// @grant           none
// ==/UserScript==

let commentContent;
function writeComment2Clipboard() {
  const commendText = commentContent.innerText;
  console.log(commendText);
  if (!commendText) return;

  navigator.clipboard.writeText(commendText).then(
    () => {
      document.title = commendText;
      console.log('clipboard successfully set');
    },
    () => {
      console.log('clipboard write failed');
    },
  );
}

document.addEventListener('click', (e) => {
  const comment = e.target.closest('[role="article"][tabindex="-1"]');
  if (comment === null) return;

  commentContent = comment.querySelector('[lang]');
  if (commentContent === null) return;

  if (e.target.getAttribute('role') === 'button') {
    setTimeout(writeComment2Clipboard, 0);
  } else {
    writeComment2Clipboard();
  }
});