Greasy Fork

Hide/Show List on OpenAI Chat(隐藏/显示gpt聊天列表)

Add a button to show/hide custom CSS on OpenAI Chat page

// ==UserScript==
// @name         Hide/Show List on OpenAI Chat(隐藏/显示gpt聊天列表)
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Add a button to show/hide custom CSS on OpenAI Chat page
// @author       Your name here
// @match        https://chat.openai.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Define your custom CSS selector here
    var customCSS = '.w-full > .overflow-x-hidden:first-of-type { display: none; }';

    // Retrieve the stored state from local storage
    var isListHidden = localStorage.getItem('isListHidden') === 'true';

    // Create a button and append it to the body
    var btn = document.createElement('button');
    btn.textContent = isListHidden ?  's' : 'h';
    btn.style.position = 'fixed';
    btn.style.bottom = '10px';
    btn.style.right = '10px';
    document.body.appendChild(btn);

    // Apply the initial state based on the stored value
    var targetElement = document.querySelector('.w-full > .overflow-x-hidden:first-of-type');
    targetElement.style.display = isListHidden ? 'none' : '';

    // When the button is clicked
    btn.addEventListener('click', function() {
        // Toggle the state
        isListHidden = !isListHidden;

        // Update the stored state in local storage
        localStorage.setItem('isListHidden', isListHidden);

        // Toggle the visibility of the target element
        targetElement.style.display = isListHidden ? 'none' : '';

        // Toggle the button text
        btn.textContent = isListHidden ? 's' : 'h';
    });
})();