Greasy Fork

来自缓存

Greasy Fork is available in English.

启用复制粘贴 (SOOP / AfreecaTV)

解除直播网站聊天输入区的复制粘贴限制。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Enable Copy and Paste (SOOP / AfreecaTV)
// @name:zh-TW   啟用複製貼上 (SOOP / AfreecaTV)
// @name:zh-CN   启用复制粘贴 (SOOP / AfreecaTV)
// @name:ja      コピーパースト有効化 (SOOP / AfreecaTV)
// @name:ko      복사 붙여넣기 활성화 (SOOP / AfreecaTV)
// @namespace    https://www.sooplive.com/
// @version      0.1
// @description  Unblock copy and paste restrictions on live streaming sites.
// @description:zh-TW 解除直播網站聊天輸入區的複製貼上限制。
// @description:zh-CN 解除直播网站聊天输入区的复制粘贴限制。
// @description:ja    ライブ配信サイトのチャット入力欄におけるコピー&ペースト制限を解除します。
// @description:ko    라이브 스트리밍 사이트의 채팅 입력창에서 복사 붙여넣기 제한을 해제합니다.
// @author       Scott
// @match        *://*.afreecatv.com/*
// @match        *://*.sooplive.co.kr/*
// @match        *://*.sooplive.com/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    /**
     * Core handler to bypass site-specific event blocking
     * Using capture phase (true) to intercept events before the site's own scripts.
     */
    const handleEvent = (e) => {
        const target = e.target;
        const isEditable = target.isContentEditable || 
                           target.tagName === 'INPUT' || 
                           target.tagName === 'TEXTAREA';

        if (isEditable) {
            // Stop the site from preventing the default behavior
            e.stopImmediatePropagation();
        }
    };

    // Register listeners on window to handle dynamically loaded elements
    window.addEventListener('paste', handleEvent, true);
    window.addEventListener('copy', handleEvent, true);
    window.addEventListener('cut', handleEvent, true);
    
    // Specifically handle context menu (right-click) blocking
    window.addEventListener('contextmenu', (e) => {
        if (e.target.isContentEditable) {
            e.stopImmediatePropagation();
        }
    }, true);

    /**
     * Force text insertion using execCommand if the native paste is intercepted 
     * or fails to sync with the frontend framework (React/Vue).
     */
    window.addEventListener('paste', function(e) {
        const target = e.target;
        if (!target.isContentEditable) return;

        const text = (e.clipboardData || window.clipboardData).getData('text/plain');
        if (!text) return;

        // Use a slight delay to ensure the manual insertion triggers framework state updates
        setTimeout(() => {
            if (target.innerText.trim() === "") {
                // 'insertText' is highly compatible with modern JS frameworks' data binding
                document.execCommand('insertText', false, text);
            }
        }, 0);
    }, true);

})();