一键清空通义千问对话

打开通义千问,左下角出现按钮,点击即可清空对话列表。

  1. "use strict";
  2. ///<reference types="tampermonkey"/>
  3. // ==UserScript==
  4. // @name 一键清空通义千问对话
  5. // @namespace https://iuroc.com
  6. // @version 1.0.0
  7. // @description 打开通义千问,左下角出现按钮,点击即可清空对话列表。
  8. // @author iuroc
  9. // @match https://tongyi.aliyun.com/qianwen
  10. // @grant GM_xmlhttpRequest
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=aliyun.com
  12. // ==/UserScript==
  13. const cookie = (() => {
  14. const v = document.cookie.match(/login_tongyi_ticket=[^;]+/);
  15. return v ? v[0] : undefined;
  16. })();
  17. const headers = {
  18. 'X-Platform': 'pc_tongyi',
  19. 'Referer': 'https://tongyi.aliyun.com/',
  20. 'Content-Type': 'application/json'
  21. };
  22. const getSessionIdList = async () => {
  23. return new Promise(resolve => {
  24. GM_xmlhttpRequest({
  25. url: 'https://qianwen.aliyun.com/querySessionList',
  26. method: 'POST',
  27. cookie,
  28. headers,
  29. onload(response) {
  30. const list = JSON.parse(response.responseText).data;
  31. const sessionId = list.map(item => item.sessionId);
  32. console.log(sessionId);
  33. resolve(sessionId);
  34. }
  35. });
  36. });
  37. };
  38. const deleteBySessionId = async (sessionId, threadCount) => {
  39. return new Promise(resolve => {
  40. GM_xmlhttpRequest({
  41. url: 'https://qianwen.aliyun.com/deleteSession',
  42. method: 'POST',
  43. cookie,
  44. headers,
  45. data: JSON.stringify({ sessionId }),
  46. onload() {
  47. threadCount.count++;
  48. resolve(null);
  49. }
  50. });
  51. });
  52. };
  53. const getCookie = () => {
  54. const v = document.cookie.match(/login_tongyi_ticket=[^;]+/);
  55. return v ? v[0] : undefined;
  56. };
  57. (async () => {
  58. 'use strict';
  59. const tool = document.createElement('div');
  60. const button = document.createElement('button');
  61. tool.style.position = 'fixed';
  62. tool.style.bottom = '30px';
  63. tool.style.left = '30px';
  64. tool.style.margin = '20px';
  65. button.onclick = async () => {
  66. if (confirm('确认要删除全部对话?')) {
  67. const sessionIdList = await getSessionIdList();
  68. let threadCount = { count: 0 };
  69. sessionIdList.forEach(async (sessionId) => {
  70. deleteBySessionId(sessionId, threadCount);
  71. });
  72. const timer = setInterval(() => {
  73. if (threadCount.count == sessionIdList.length) {
  74. clearInterval(timer);
  75. location.reload();
  76. }
  77. }, 100);
  78. }
  79. };
  80. button.innerHTML = '删除全部对话';
  81. tool.appendChild(button);
  82. document.body.appendChild(tool);
  83. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址