Enable pasting

Enables pasting in Human or Not game

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Enable pasting
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Enables pasting in Human or Not game
// @author       suggestingpain
// @match        https://*.humanornot.ai/
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to handle pasting text
    function handlePaste(event) {
        // Prevent default paste behavior
        event.preventDefault();

        // Get text from clipboard
        const clipboardData = event.clipboardData || window.clipboardData;
        const pastedText = clipboardData.getData('text');

        // Insert pasted text into the contentEditable div
        const div = event.target;
        const selection = window.getSelection();
        if (selection.rangeCount > 0) {
            const range = selection.getRangeAt(0);
            range.deleteContents();
            range.insertNode(document.createTextNode(pastedText));
        }
    }

    // Function to check for new contentEditable divs
    function checkForNewDivs() {
        const divs = document.querySelectorAll('div[contentEditable="true"]:not(.handled)');
        divs.forEach(div => {
            div.classList.add('handled');
            div.addEventListener('paste', handlePaste);
        });
    }

    // Polling function to periodically check for new contentEditable divs
    function pollForNewDivs() {
        setInterval(checkForNewDivs, 100);
    }

    // Start polling for new divs
    pollForNewDivs();
})();