Browse Source

新增代码压缩工具;ChatGPT增加api-key自助配置入口;其他bug一并修复

[email protected] 2 years ago
parent
commit
4346a91eaf

+ 1 - 1
apps/background/awesome.js

@@ -155,7 +155,7 @@ let Awesome = (() => {
                 }
             });
             Object.keys(toolMap).forEach(tool => {
-                toolMap[tool].installed = toolMap[tool].installed || toolMap[tool].offloadForbid;
+                toolMap[tool].installed = toolMap[tool].systemInstalled || toolMap[tool].installed;
             });
             return toolMap;
         });

+ 0 - 1
apps/background/menu.js

@@ -64,7 +64,6 @@ export default (function () {
                     };
                     break;
 
-
                 case 'qr-code':
                     toolMap[tool].menuConfig[0].onClick = function (info, tab) {
                         chrome.scripting.executeScript({

+ 9 - 1
apps/background/tools.js

@@ -4,7 +4,7 @@ let toolMap = {
         tips: '页面自动检测并格式化、手动格式化、乱码解码、排序、BigInt、编辑、下载、皮肤定制等',
         contentScriptJs: true,
         contentScriptCss: true,
-        offloadForbid: true,
+        systemInstalled: true,
         menuConfig: [{
             icon: '⒥',
             text: 'JSON格式化',
@@ -62,6 +62,14 @@ let toolMap = {
             contexts: ['page', 'selection', 'editable']
         }]
     },
+    'code-compress': {
+        name: '代码压缩工具',
+        tips: 'Web开发用,提供简单的代码压缩功能,支持HTML、Javascript、CSS代码压缩',
+        menuConfig: [{
+            icon: '♯',
+            text: '代码压缩工具'
+        }]
+    },
     'chatgpt': {
         name: 'ChatGPT工具',
         tips: '由OpenAI强力支撑的超智能对话工具,可以让它帮你写代码、查资料、做分析、甚至帮你画一幅画',

+ 7 - 0
apps/chatgpt/index.html

@@ -39,6 +39,13 @@
                             <input type="radio" name="rdoImgSize" value="1024x1024" v-model="imgSize" id="rdoImgSize_1024"><label for="rdoImgSize_1024">1024*1024</label>
                         </div>
                     </fieldset>
+
+                    <fieldset>
+                        <legend>设置API-KEY</legend>
+                        <div>
+                            <input type="text" id="elmApiKey" class="form-control" v-model="authKey">
+                        </div>
+                    </fieldset>
                     <div class="x-sure">
                         <input class="btn btn-sm btn-primary ui-mr-10" type="button" value="取消" @click="toggleSettingPanel()">
                         <input class="btn btn-sm btn-success" type="button" value="确定" @click="saveSettings()">

+ 10 - 4
apps/chatgpt/index.js

@@ -34,6 +34,10 @@ new Vue({
     mounted: function () {
         this.$refs.prompt.focus();
         this.authKey = this.decodeAuthKey(this.$refs.prompt.getAttribute('data-key'));
+        // 如果本地有存储过authKey,就优先用本地的
+        Awesome.StorageMgr.get('CHATGPT_AUTH_KEY').then(authKey => {
+            this.authKey = authKey || this.authKey;
+        });
 
         Awesome.StorageMgr.get('CHATGPT_CONVERSATION').then(results => {
             if(results && results.length) {
@@ -93,6 +97,10 @@ new Vue({
                     // 鉴权失败
                     if(resp.status == 401) {
                         json.errorMessage = '出错啦!ChatGPT鉴权失败!';
+                    } else if(resp.status == 429) {
+                        let url = 'https://beta.openai.com/account/api-keys';
+                        json.errorMessage = '当前账号下OpenAI的免费限额用完了,你可以在右上角【机器人设置】中更换为你自己的OpenAI API Key!'
+                            + `如果你还没有OpenAI账号,<a class="resp-tips" target="_blank" href="${url}">你可以点击这里进入</a>,提前申请好API Key!`;
                     } else {
                         json.errorMessage = '发生未知错误,请稍后再试!';
                     }
@@ -190,7 +198,8 @@ new Vue({
             this.showSettingPanel = false;
             Awesome.StorageMgr.set('CHATGPT_IMAGE_SIZE',this.imgSize);
             Awesome.StorageMgr.set('CHATGPT_CHAT_MODEL',this.chatModel);
-            toast('设置成功,已立即生效!');
+            Awesome.StorageMgr.set('CHATGPT_AUTH_KEY',this.authKey);
+            toast('设置成功,已立即生效,可以继续使用了!');
         },
         imageBase64(onlineSrc) {
             let that = this;
@@ -220,9 +229,6 @@ new Vue({
         },
         decodeAuthKey(dataKey){
             return EncodeUtils.utf8Decode(EncodeUtils.base64Decode(dataKey));
-        },
-        loadApiKey(){
-
         }
     }
 

+ 1 - 1
apps/manifest.json

@@ -1,7 +1,7 @@
 {
   "name": "FeHelper(前端助手)-Dev",
   "short_name": "FeHelper",
-  "version": "2022.12.2716",
+  "version": "2023.01.0512",
   "manifest_version": 3,
   "description": "JSON自动格式化、手动格式化,支持排序、解码、下载等,更多功能可在配置页按需安装!",
   "icons": {

+ 2 - 2
apps/options/index.html

@@ -110,8 +110,8 @@
                     <span class="x-tips">({{fhTools[tool].tips}})</span>
 
                     <span class="ui-fl-r x-btn-box">
-                        <button class="btn btn-danger btn-xs" @click="offLoad(tool,$event)" v-if="!fhTools[tool].offloadForbid">卸载</button>
-                        <button class="btn btn-disabled btn-xs" v-if="fhTools[tool].offloadForbid" title="系统预装,不可被卸载">卸载</button>
+                        <button class="btn btn-danger btn-xs" @click="offLoad(tool,$event)" v-if="!fhTools[tool].systemInstalled">卸载</button>
+                        <button class="btn btn-disabled btn-xs" v-if="fhTools[tool].systemInstalled" title="系统预装,不可被卸载">卸载</button>
                         <button class="btn btn-xs" :class="fhTools[tool].menu ? 'btn-warning' : 'btn-info'" @click="menuMgr(tool,$event)">{{fhTools[tool].menu ? '移出' : '加入'}}右键</button>
                     </span>
 

BIN
output/fehelper.zip