ChatGPT Temporary Chat Toggle without reloading the web

Toggle temporary chat mode on chaptgpt with double shift key press without reloading

Versión del día 31/12/2024. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         ChatGPT Temporary Chat Toggle without reloading the web
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Toggle temporary chat mode on chaptgpt with double shift key press without reloading
// @author       小红书 :沉浸式学法语😈  小红书id : 590862748
// @match        https://chatgpt.com/*
// @license MIT
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    var lastShiftTime = 0;
    var shiftTimeout = 500;
    var shiftPressedOnce = false;
    var savedChatChannel = null; // To store the current chat channel for switching back

    document.addEventListener('keydown', function (e) {
        if (e.key === 'Shift') {
            var currentTime = new Date().getTime();
            if (shiftPressedOnce && (currentTime - lastShiftTime) < shiftTimeout) {
                shiftPressedOnce = false;
                lastShiftTime = 0;

                toggleTemporaryChat();
            } else {
                shiftPressedOnce = true;
                lastShiftTime = currentTime;

                setTimeout(function () {
                    shiftPressedOnce = false;
                }, shiftTimeout);
            }
        }
    });

    function toggleTemporaryChat() {
        var url = new URL(window.location.href);
        var params = new URLSearchParams(url.search);

        if (params.get('temporary-chat') === 'true') {
            if (savedChatChannel) {
                history.replaceState(null, '', savedChatChannel);
                savedChatChannel = null; // Clear the saved channel after restoring
            } else {
                history.replaceState(null, '', '/');
            }
        } else {
            if (url.pathname.startsWith('/c/')) {
                savedChatChannel = url.pathname + url.search + url.hash;
            }
            params.set('temporary-chat', 'true');
            history.replaceState(null, '', `/?${params.toString()}`);
        }

        triggerUrlChange();
    }

    function triggerUrlChange() {
        // Some SPAs listen to the popstate event
        window.dispatchEvent(new PopStateEvent('popstate', { state: history.state }));
    }
})();
// ==Copyright==
// Copyright © 2024 by 沉浸式学法语😈 (小红书 ID: 590862748). All rights reserved.
// This script is the intellectual property of the author. Unauthorized copying, modification,
// or redistribution of this script, in whole or in part, is strictly prohibited without explicit
// prior written permission from the author.
// For inquiries, contact the author through their 小红书 ID: 590862748.
// ==End of Copyright==