ChatGPT Temporary Chat Toggle without reloading the web

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

Verze ze dne 01. 01. 2025. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         ChatGPT Temporary Chat Toggle without reloading the web
// @namespace    http://tampermonkey.net/
// @version      0.5
// @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';

    const DOUBLE_TAP_TIMEOUT = 500;
    let firstShiftPressTime = null;
    let isShiftHeld = false;
    let savedChatChannel = null; 

    document.addEventListener('keydown', handleKeyDown);
    document.addEventListener('keyup', handleKeyUp);

    function handleKeyDown(e) {
        if (e.key !== 'Shift') return;

        if (isShiftHeld) {
            return;
        }

        const currentTime = Date.now();
        isShiftHeld = true;

        if (firstShiftPressTime && currentTime - firstShiftPressTime <= DOUBLE_TAP_TIMEOUT) {
            toggleTemporaryChat();
            firstShiftPressTime = null; 
        } else {
            firstShiftPressTime = currentTime;
        }
    }

    function handleKeyUp(e) {
        if (e.key === 'Shift') {
            isShiftHeld = false;
        }
    }

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

        if (params.get('temporary-chat') === 'true') {
            if (savedChatChannel) {
                history.replaceState(null, '', savedChatChannel);
                savedChatChannel = null;
            } 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()}`);
        }

        // trigger URL change event for SPA frameworks
        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==