KeepChatGPT icon indicating copy to clipboard operation
KeepChatGPT copied to clipboard

能否阻止本地显示的文本被删除?

Open eprtr opened this issue 1 year ago • 6 comments

就是AI的输出内容触发警告时,可以阻止已经输出到页面上的内容被删除。

eprtr avatar Aug 28 '23 02:08 eprtr

用gpt4.0写的油猴,右下角有一个浮动的按钮,不用的时候关掉就行了。 KeepChatGPT也需要保持开启,不然会收到警告邮件。 用于临时应付一下,还是要等大佬更新插件

// ==UserScript==
// @name         防止chatGPT把已输出的内容删掉(beta)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Log changes to div with class result-streaming
// @author       You
// @match        https://chat.openai.com/*
// @icon         https://chat.openai.com/favicon.ico
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    let isEnabled = true;

    // 创建美观的浮动开关
    const switchContainer = document.createElement('div');
    switchContainer.style.position = 'fixed';
    switchContainer.style.bottom = '20px';
    switchContainer.style.right = '20px';
    switchContainer.style.zIndex = '9999';
    switchContainer.style.backgroundColor = '#f1f1f1';
    switchContainer.style.border = '1px solid #ccc';
    switchContainer.style.borderRadius = '12px';
    switchContainer.style.padding = '10px';
    switchContainer.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.1)';
    switchContainer.style.cursor = 'pointer';
    switchContainer.style.userSelect = 'none';

    const switchLabel = document.createElement('label');
    switchLabel.innerHTML = 'Enable Feature: ';
    switchLabel.style.marginRight = '10px';
    switchLabel.style.fontFamily = 'Arial, sans-serif';
    switchLabel.style.cursor = 'pointer';

    const switchInput = document.createElement('input');
    switchInput.type = 'checkbox';
    switchInput.checked = isEnabled;

    switchContainer.addEventListener('click', function() {
        isEnabled = !isEnabled;
        switchInput.checked = isEnabled;
    });

    switchContainer.appendChild(switchLabel);
    switchContainer.appendChild(switchInput);
    document.body.appendChild(switchContainer);

    function handleMutations(mutations) {
        if (!isEnabled) return;

        for (const mutation of mutations) {
            if (mutation.type === 'childList') {
                mutation.removedNodes.forEach((node) => {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        if (node.matches('div.result-streaming')) {
                            console.log('Attempt to delete div.result-streaming detected. Reverting.');
                            mutation.target.appendChild(node);
                        }
                    }
                });
            }
        }
    }

    const bodyObserver = new MutationObserver(handleMutations);
    const config = { childList: true, subtree: true };
    bodyObserver.observe(document.body, config);
})();

qwetank avatar Aug 30 '23 07:08 qwetank

What does this script do?

mistrobot avatar Aug 30 '23 14:08 mistrobot

用gpt4.0写的油猴,右下角有一个浮动的按钮,不用的时候关掉就行了。 KeepChatGPT也需要保持开启,不然会收到警告邮件。 用于临时应付一下,还是要等大佬更新插件

// ==UserScript==
// @name         防止chatGPT把已输出的内容删掉(beta)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Log changes to div with class result-streaming
// @author       You
// @match        https://chat.openai.com/*
// @icon         https://chat.openai.com/favicon.ico
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    let isEnabled = true;

    // 创建美观的浮动开关
    const switchContainer = document.createElement('div');
    switchContainer.style.position = 'fixed';
    switchContainer.style.bottom = '20px';
    switchContainer.style.right = '20px';
    switchContainer.style.zIndex = '9999';
    switchContainer.style.backgroundColor = '#f1f1f1';
    switchContainer.style.border = '1px solid #ccc';
    switchContainer.style.borderRadius = '12px';
    switchContainer.style.padding = '10px';
    switchContainer.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.1)';
    switchContainer.style.cursor = 'pointer';
    switchContainer.style.userSelect = 'none';

    const switchLabel = document.createElement('label');
    switchLabel.innerHTML = 'Enable Feature: ';
    switchLabel.style.marginRight = '10px';
    switchLabel.style.fontFamily = 'Arial, sans-serif';
    switchLabel.style.cursor = 'pointer';

    const switchInput = document.createElement('input');
    switchInput.type = 'checkbox';
    switchInput.checked = isEnabled;

    switchContainer.addEventListener('click', function() {
        isEnabled = !isEnabled;
        switchInput.checked = isEnabled;
    });

    switchContainer.appendChild(switchLabel);
    switchContainer.appendChild(switchInput);
    document.body.appendChild(switchContainer);

    function handleMutations(mutations) {
        if (!isEnabled) return;

        for (const mutation of mutations) {
            if (mutation.type === 'childList') {
                mutation.removedNodes.forEach((node) => {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        if (node.matches('div.result-streaming')) {
                            console.log('Attempt to delete div.result-streaming detected. Reverting.');
                            mutation.target.appendChild(node);
                        }
                    }
                });
            }
        }
    }

    const bodyObserver = new MutationObserver(handleMutations);
    const config = { childList: true, subtree: true };
    bodyObserver.observe(document.body, config);
})();

谢谢!

eprtr avatar Aug 31 '23 06:08 eprtr

What does this script do?

this is Tampermonkey script

eprtr avatar Aug 31 '23 06:08 eprtr

I know, but does this fix the cancel audit function or still no?

mistrobot avatar Aug 31 '23 08:08 mistrobot

改了一点点,阻止 最近输入 的显示被删除,不过内部的实际内容已经被清空

                        if (node.matches('div.result-streaming') || node.className === 'empty:hidden') {
                            console.log(`Attempt to delete ${node.tagName}.${node.className} detected. Reverting.`);

OrochiZ avatar Sep 09 '23 04:09 OrochiZ