From dc070e5bc5139b65501842ada0a2ab93669e42ad Mon Sep 17 00:00:00 2001 From: gantrol Date: Mon, 5 Jun 2023 21:25:01 +0800 Subject: [PATCH] release: v0.2.5 quick fix for multipart answer --- package.json | 2 +- utils/bingPage.ts | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index b3e6a98..9578384 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bing-chat-saver", "displayName": "Bing Chat saver", - "version": "0.2.4", + "version": "0.2.5", "description": "Saving Bing Chat for you, for sharing", "author": "gantrol", "scripts": { diff --git a/utils/bingPage.ts b/utils/bingPage.ts index 30ec0a9..754c61c 100644 --- a/utils/bingPage.ts +++ b/utils/bingPage.ts @@ -27,8 +27,8 @@ export class Page { return Page.getMain().querySelector("cib-chat-turn") .shadowRoot.querySelector("cib-message-group:nth-child(1)") .shadowRoot.querySelector("cib-message") - .shadowRoot.querySelector("cib-shared > div.content.text-message-content").textContent - } + .shadowRoot.querySelector("cib-shared > div.content.text-message-content").textContent; + }; static handleRefs = (ansFrame: HTMLElement, setFontWeight = true, returnJSON = false) => { // ansFrame's css selector is cib-message[type="text"] @@ -105,9 +105,9 @@ export class Page { }; static getCleanButton = () => { - return Page.getWhole().querySelector("#cib-action-bar-main") + return Page.getWhole().querySelector("#cib-action-bar-main") .shadowRoot.querySelector(".button-compose"); - } + }; } export class QAList { @@ -135,6 +135,9 @@ export class QAList { for (let group of groups_root.querySelectorAll("cib-message-group")) { // check user or bot + // TODO: may be multiple + // querySelector("#cib-chat-main > cib-chat-turn:nth-child(4)").shadowRoot + // .querySelector("cib-message-group.response-message-group").shadowRoot.querySelector("cib-message:nth-child(2)") if (group.getAttribute("source") === "bot") { // Answer const answer = { @@ -154,18 +157,23 @@ export class QAList { .textContent?.trim(); }); // body, optional, e.g., meta is loading, but wss does not response - const ansFrame = messagesShadowRoot.querySelector("cib-message[type=\"text\"]"); - if (ansFrame) { - const ansHTML = ansFrame - .shadowRoot.querySelector("div.ac-textBlock"); - // fix: Cannot read properties of null (reading 'innerHTML') - if (ansHTML) { - answer.html = ansHTML.innerHTML; - answer.text = ansHTML.textContent?.trim(); + const ansFrames = messagesShadowRoot.querySelectorAll("cib-message[type=\"text\"]"); + for (let ansFrame of ansFrames) { + debugger; + if (ansFrame) { + const ansHTML = ansFrame + .shadowRoot.querySelector("div.ac-textBlock"); + // fix: Cannot read properties of null (reading 'innerHTML') + if (ansHTML) { + // 间隔会不会有问题 + answer.html += ansHTML.innerHTML; + answer.text += ansHTML.textContent?.trim(); + } + // Note: refs is optional + answer.refs.concat(Page.handleRefs(ansFrame, false, true)); + } } - // Note: refs is optional - answer.refs = Page.handleRefs(ansFrame, false, true); if (answer.text !== "") { console.log(answer); QA.answers.push(answer);