Greasy Fork

Greasy Fork is available in English.

Kimi History Eraser

Help you delete all your kimi history!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Kimi History Eraser
// @namespace    http://tampermonkey.net/
// @version      2025-01-08
// @description  Help you delete all your kimi history!
// @author       xqm32
// @match        https://kimi.moonshot.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=moonshot.cn
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    "use strict";
    const deleteAll = async () => {
        const token = window.localStorage.getItem("access_token");
        const chatListResp = await fetch("https://kimi.moonshot.cn/api/chat/list", {
            method: "POST",
            headers: {
                Authorization: `Bearer ${token}`,
                "Content-Type": "application/json",
            },
            body: "{}",
        });
        const chatList = await chatListResp.json();
        await Promise.all(
            chatList.items.map(async (chat) => {
                await fetch(`https://kimi.moonshot.cn/api/chat/${chat.id}`, {
                    method: "DELETE",
                    headers: { Authorization: `Bearer ${token}` },
                });
            })
        );
        window.alert(`已删除${chatList.items.length}条`);
        window.location.reload();
    };
    new MutationObserver(() => {
        document.getElementById("deleteAll")?.remove();
        const element = document.querySelector(".history-modal-title");
        if (element === null) return;
        const deleteElement = document.createElement("button");
        element.after(deleteElement);
        deleteElement.id = "deleteAll";
        deleteElement.innerHTML = "删除所有历史对话";
        deleteElement.onclick = deleteAll;
    }).observe(document.querySelector("head"), {
        childList: true,
    });
})();