Skip to content

Commit

Permalink
chrome plugin for zhihu
Browse files Browse the repository at this point in the history
  • Loading branch information
no13bus authored and no13bus committed Dec 6, 2022
1 parent 4130f47 commit 8796504
Show file tree
Hide file tree
Showing 15 changed files with 608 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
build/
background.js
.DS_Store
*.zip
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 no13bus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# chat-gpt-zhihu-extension
ChatGPT的知乎回答小帮手,利用AI来协助你回答知乎问题
# 插件说明

一个知乎的 chatgpt 浏览器小插件,可作为你回复问题的参考,也可以复制 chatgpt 的结果到回答的编辑器中进行相应的修改。

注意: 插件使用的前提是你需要有一个自己的 chatgpt 账号, 注册地址 https://chat.openai.com/)

## 软件截图和操作视频

[操作视频](https://www.bilibili.com/video/BV1T84y1r7wy/?share_source=copy_web&vd_source=ae0fecf5ed4742e42e47340480aa174f)

![Screenshot](screenshot.png?raw=true)

## 安装

### chrome 应用商店安装(todo 审核中)

### 本地安装

1. 下载 `chrome.zip` from [Releases](https://github.com/no13bus/chat-gpt-zhihu-extension/releases)
2. 解压 zip
3. 打开网址 `chrome://extensions`.
4. 打开开发者模式.
5. 将解压包拖到当前页面,或者手动引入也可以.

## 本地构建

1. clone
2. 运行命令 `npm install`
3. 执行 `./build.sh`
4. 加载 `build` 文件夹到你的 chrome 中

## todos

- [ ] chrome 应用市场审核通过
- [ ] 直接在回答的编辑器里面增加按钮,点击按钮即可把 chatgpt 的回答放置到编辑器中。

## 致谢

项目的想法来自于 wong2 的项目 [wong2/chat-gpt-google-extension](https://github.com/wong2/chat-gpt-google-extension), 感谢他做了这么棒的项目,让我看到了更多的可能性。

我也在想,未来会不会我们自己也分辨不清,有些文章和回答是人写的呢,还是机器写的呢?whatever.
11 changes: 11 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

rm -rf build

npx esbuild src/content-script/index.mjs src/background/index.mjs --bundle --outdir=build

cp src/*.css build/
cp src/*.png build/

MANIFEST_PATH=$([[ $1 == "firefox" ]] && echo "src/manifest.v2.json" || echo "src/manifest.json")
cp $MANIFEST_PATH build/manifest.json
206 changes: 206 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "chat-gpt-zhihu-extension",
"version": "1.0.0",
"main": "background.js",
"keywords": [],
"author": "no13bus",
"license": "ISC",
"dependencies": {
"esbuild": "^0.15.17",
"eventsource-parser": "^0.0.5",
"expiry-map": "^2.0.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"webextension-polyfill": "^0.10.0"
}
}
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/background/fetch-sse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createParser } from "eventsource-parser";
import { streamAsyncIterable } from "./stream-async-iterable.mjs";

export async function fetchSSE(resource, options) {
const { onMessage, ...fetchOptions } = options;
const resp = await fetch(resource, fetchOptions);
const parser = createParser((event) => {
if (event.type === "event") {
onMessage(event.data);
}
});
for await (const chunk of streamAsyncIterable(resp.body)) {
const str = new TextDecoder().decode(chunk);
parser.feed(str);
}
}
Loading

0 comments on commit 8796504

Please sign in to comment.