Skip to content

Commit

Permalink
修复JSON bigint key失真问题;修复chatgpt工具小bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xianliezhao@foxmail.com committed Mar 22, 2023
1 parent 371059f commit 677aed6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions apps/chatgpt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ new Vue({
if(this.showLoading) return;
let sendTime = (new Date()).format('yyyy/MM/dd HH:mm:ss');
// 先加入队列,先展示,获取成功后会移除
this.results.push({sendTime,message:configs.data.prompt});
let prompt = configs.data.prompt || configs.data.messages[0].content;
this.results.push({sendTime,message:prompt});
this.toggleLoading();
this.$nextTick(() => {
this.letMsgScrollIntoView();
Expand Down Expand Up @@ -126,7 +127,7 @@ new Vue({

return configs.buildResponse(json).then(respContent => {
this.results.pop(); // 把最后一个节点移除掉,重新添加一个干净的
this.results.push({ id,sendTime,message:configs.data.prompt,respTime,respContent });
this.results.push({ id,sendTime,message:prompt,respTime,respContent });
this.saveConversation();
this.toggleLoading();
this.$nextTick(() => {
Expand Down Expand Up @@ -159,7 +160,7 @@ new Vue({
return new Promise(resolve => {
let respText ;
if(this.isGPT35) {
respText = json.choices[0].message.coontent.replace(/^\?\n\n/,'')
respText = json.choices[0].message.content.replace(/^\?\n\n/,'')
}else{
respText = json.choices[0].text.replace(/^\?\n\n/,'');
}
Expand Down
4 changes: 3 additions & 1 deletion apps/code-beautify/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ window.codebeautifyContentScript = (() => {
// 用webwork的方式来进行格式化,效率更高
let worker = new Worker(URL.createObjectURL(new Blob(["(" + highlightWebWorker.toString() + ")()"], {type: 'text/javascript'})));
worker.onmessage = (event) => {
code.innerHTML = "<ol><li><span>" + event.data.replace(/\n/gm, '</span></li><li><span>') + '</span></li></ol>';
code.innerHTML = "<ol><li><span>" + event.data
.replace(/</gm,'&lt;').replace(/>/gm,'&gt;')
.replace(/\n/gm, '</span></li><li><span>') + '</span></li></ol>';
callback && callback();
};
worker.postMessage(txtResult);
Expand Down
10 changes: 10 additions & 0 deletions apps/json-format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ new Vue({
}
// 这里可能会throw exception
jsonObj = JSON.parse(source);

} catch (ex) {
// new Function的方式,能自动给key补全双引号,但是不支持bigint,所以是下下策,放在try-catch里搞
try {
Expand All @@ -127,6 +128,15 @@ new Vue({
}
}

try{
// 这里多做一个动作,给没有携带双引号的Key都自动加上,防止Long类型失真
const regex = /([{,]\s*)(\w+)(\s*:)/g;

This comment has been minimized.

Copy link
@arsentiii

arsentiii Mar 27, 2023

bug here?
需要考虑value中含有 逗号 , 会被处理的问题.
image

#257

source = source.replace(regex, '$1"$2"$3');
jsonObj = JSON.parse(source);
}catch(e){
this.errorMsg = e.message;
}

// 是json格式,可以进行JSON自动格式化
if (jsonObj != null && typeof jsonObj === "object" && !this.errorMsg.length) {
try {
Expand Down
2 changes: 1 addition & 1 deletion apps/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "FeHelper(前端助手)-Dev",
"short_name": "FeHelper",
"version": "2023.03.0410",
"version": "2023.03.2212",
"manifest_version": 3,
"description": "JSON自动格式化、手动格式化,支持排序、解码、下载等,更多功能可在配置页按需安装!",
"icons": {
Expand Down
Binary file modified output/fehelper.zip
Binary file not shown.

0 comments on commit 677aed6

Please sign in to comment.