Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
release: v0.2.5 quick fix for multipart answer
Browse files Browse the repository at this point in the history
  • Loading branch information
gantrol committed Jun 5, 2023
1 parent ee6bb01 commit dc070e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
36 changes: 22 additions & 14 deletions utils/bingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -105,9 +105,9 @@ export class Page {
};

static getCleanButton = () => {
return <HTMLElement> Page.getWhole().querySelector("#cib-action-bar-main")
return <HTMLElement>Page.getWhole().querySelector("#cib-action-bar-main")
.shadowRoot.querySelector(".button-compose");
}
};
}

export class QAList {
Expand Down Expand Up @@ -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 = {
Expand All @@ -154,18 +157,23 @@ export class QAList {
.textContent?.trim();
});
// body, optional, e.g., meta is loading, but wss does not response
const ansFrame = <HTMLElement>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(<HTMLElement>ansFrame, false, true));

}
}
// Note: refs is optional
answer.refs = Page.handleRefs(ansFrame, false, true);
if (answer.text !== "") {
console.log(answer);
QA.answers.push(answer);
Expand Down

0 comments on commit dc070e5

Please sign in to comment.