Discord Copy/Paste

bypass copy and paste restriction on the Discord website

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Discord Copy/Paste
// @namespace   discord-copy-paste
// @version     1.0
// @description bypass copy and paste restriction on the Discord website
// @author      icycoldveins
// @match       https://discord.com/*
// @grant       none
// @license     MIT

// ==/UserScript==

(function () {
  'use strict';

  function copySelectedText() {
    const selection = window.getSelection();
    const messageElement = selection.anchorNode.closest('.message');
    if (!messageElement) return;
    navigator.clipboard.writeText(selection.toString());
  }

  function copyMessageContent() {
    const messageElement = document.activeElement.closest('.message');
    if (!messageElement) return;
    const messageContent = messageElement.querySelector('.message-content');
    navigator.clipboard.writeText(messageContent.textContent.trim());
  }

  function pasteClipboardContent() {
    navigator.clipboard.readText().then((text) => {
      document.activeElement.value += text;
    });
  }

  document.addEventListener('keydown', (event) => {
    if (event.ctrlKey) {
      if (event.key === 'c') {
        copySelectedText();
      } else if (event.key === 'v') {
        pasteClipboardContent();
      }
    } else if (event.shiftKey) {
      if (event.key === 'c') {
        copyMessageContent();
      } 
    }
  });
})();