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

Commit

Permalink
Merge pull request #7 from 3kinglee/feat/end-syntax
Browse files Browse the repository at this point in the history
Feat/end syntax & user avatar
  • Loading branch information
3kinglee authored Feb 27, 2023
2 parents c69f6b5 + 7124779 commit c93a99c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
42 changes: 21 additions & 21 deletions extension/contentScript/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ai-chat-export",
"version": "0.0.1",
"version": "0.0.2",
"manifest_version": 3,
"author": "[email protected]",
"description": "export ai-chat page as yaml",
Expand Down
22 changes: 20 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ export const getChatObject = () => {
const elements = document.querySelectorAll("[class*='min-h-[20px]']");
if (elements.length <= 0) return;

const questionnerAvatar = getQuestionerAvatarUrl();

const defaultJson = {
$schema: "Dialog",
Dialog: {
title: "chatGPT对话",
characters: [
{
name: "questioner",
avatar: "https://res.pandateacher.com/7KJKIMIE1677146652086.png",
avatar:
questionnerAvatar ||
"https://res.pandateacher.com/1O2BGDK91671292227563.jpg",
},
{
name: "AI",
Expand All @@ -41,7 +45,7 @@ export const getChatObject = () => {
},
};

const contents = [];
let contents = [];

elements.forEach((ele) => {
const firstChild = ele.firstChild;
Expand Down Expand Up @@ -83,6 +87,20 @@ export const getChatObject = () => {
contents.push(contentObj);
});

const endContents = [{ CourseFinished: null }, { End: null }];
contents = [...contents, ...endContents];
defaultJson.Dialog.contents = contents;
return defaultJson;
};

export const getQuestionerAvatarUrl = () => {
let avatarUrl = Array.from(
document.querySelectorAll("[class*='w-[30px]']")[0]?.querySelectorAll("img")
).find((item) => item.currentSrc.startsWith("https"))?.currentSrc;

if (/\?url=/.test(avatarUrl)) {
const url = avatarUrl.split("url=")[1];
avatarUrl && (avatarUrl = decodeURIComponent(url));
}
return avatarUrl;
};

0 comments on commit c93a99c

Please sign in to comment.