Enable pasting

Enables pasting in Human or Not game

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();