Greasy Fork is available in English.

Bing Chat Conversations Deleter

Deletes all recent conversations from Bing Chat.

// ==UserScript==
// @name       Bing Chat Conversations Deleter
// @namespace   Violentmonkey Scripts
// @match       https://www.bing.com/*
// @license     MIT
// @version     3.0
// @author      Reddiepoint
// @description Deletes all recent conversations from Bing Chat.
// ==/UserScript==

(function() {
    'use strict';

    function waitForElement(selector) {
        return new Promise(resolve => {
            const interval = setInterval(() => {
                const element = document.querySelector(selector);
                if (element) {
                    clearInterval(interval);
                    resolve(element);
                }
            }, 10);
        });
    }

    async function deleteConversations() {
        const sidePanel = await waitForElement("#b_sydConvCont > cib-serp");
        const sidePanelShadowRoot = sidePanel.shadowRoot;
        const mainDiv = sidePanelShadowRoot.querySelector("#cib-conversation-main > cib-side-panel");
        const mainDivShadowRoot = mainDiv.shadowRoot;
        const threadsContainer = mainDivShadowRoot.querySelector("#cib-threads-container");

        // Assuming threads are direct children of threadsContainer
        const threads = threadsContainer.querySelectorAll("cib-thread");
        for (let i = 0; i < threads.length; i++) {
            let threadShadowRoot = threads[i].shadowRoot;
            let deleteButton = threadShadowRoot.querySelector("div > div > div.controls > button.delete.icon-button");
            if (deleteButton) {
                deleteButton.click();
                // Wait for the confirmation dialog to appear and confirm deletion
                await new Promise(resolve => setTimeout(resolve, 10)); // Adjust timing as necessary
                let confirmButton = threadShadowRoot.querySelector("div > div > div.controls > button.confirm.icon-button");
                if (confirmButton) {
                    confirmButton.click();
                }
                // Add delay to allow for the deletion to process before continuing
                await new Promise(resolve => setTimeout(resolve, 100)); // Adjust timing as necessary
            }
        }
        // Optionally, refresh or navigate to update the UI after deletion
    }

    async function addButton() {
        const sidePanel = await waitForElement("#b_sydConvCont > cib-serp");
        const sidePanelShadowRoot = sidePanel.shadowRoot;
        const mainDiv = sidePanelShadowRoot.querySelector("#cib-conversation-main > cib-side-panel");
        const mainDivShadowRoot = mainDiv.shadowRoot;
        const div = mainDivShadowRoot.querySelector("div.main > div > div > div");

        const button = document.createElement("button");
        button.innerText = "Delete all personal conversations";
        button.addEventListener("click", deleteConversations);
        div.appendChild(button);
    }

    addButton();
})();