瀏覽代碼

转义后的JSON也自动支持格式化

zxlie 7 年之前
父節點
當前提交
3c91c43ff4

+ 1 - 1
README.md

@@ -31,7 +31,7 @@ https://chrome.google.com/webstore/detail/pkgccpejnmalmdinmhkkfafefagiiiad?hl=zh
 - 代码压缩工具(HTML/CSS/JS)
 - 二维码生成器(支持当前页面、图片、链接、选中的文字生成QrCode)
 - 二维码解码器(支持网页二维码`右键`解码)
-- 网页转为图片(将当前整个网页转为图片并保存)
+- 网页滚动截屏(将当前整个网页转为图片并保存)
 - Markdown转换(支持Markdown与HTML的互转)
 - 页面取色工具(滑动鼠标随意取色)
 - Js正则表达式(正则测试、常用正则列表)

+ 1 - 1
apps/background/index.js

@@ -402,7 +402,7 @@ var BgPageInstance = (function () {
             parentId: feHelper.contextMenuId
         });
         chrome.contextMenus.create({
-            title: "✂  网页转为图片",
+            title: "✂  网页滚动截屏",
             contexts: ['all'],
             parentId: feHelper.contextMenuId,
             onclick: function (info, tab) {

+ 12 - 6
apps/json-format/automatic.js

@@ -142,17 +142,23 @@ module.exports = (() => {
             // 这里可能会throw exception
             jsonObj = JSON.parse(source);
         } catch (ex) {
+
             // new Function的方式,能自动给key补全双引号,但是不支持bigint,所以是下下策,放在try-catch里搞
             try {
                 jsonObj = new Function("return " + source)();
-                // 还要防止下面这种情况:  "{\"ret\":\"0\", \"msg\":\"ok\"}"
-                if (typeof jsonObj === "string") {
-                    // 再来一次
-                    jsonObj = new Function("return " + jsonObj)();
-                }
             } catch (exx) {
-                return;
+                try{
+                    // 再给你一次机会,是不是下面这种情况:  "{\"ret\":\"0\", \"msg\":\"ok\"}"
+                    jsonObj = new Function("return '" + source + "'")();
+                    if(typeof jsonObj === 'string') {
+                        // 最后给你一次机会,是个字符串,老夫给你再转一次
+                        jsonObj = new Function("return " + jsonObj)();
+                    }
+                }catch(exxx){
+                    return ;
+                }
             }
+
         }
 
         // 是json格式,可以进行JSON自动格式化

+ 0 - 10
apps/json-format/format-lib.js

@@ -252,16 +252,6 @@ var JsonFormatEntrance = (function () {
      */
     var format = function (jsonStr) {
 
-        // 如果jsonStr和上一次的一模一样,就不用再格式化了
-        try {
-            var str1 = JSON.stringify(JSON.parse(jsonStr));
-            var str2 = JSON.stringify(JSON.parse(pre.innerText));
-            if (str1 == str2) {
-                return false;
-            }
-        } catch (e) {
-        }
-
         try {
             jfContent.innerHTML = '';
             pre.innerHTML = '';

+ 3 - 0
apps/json-format/index.css

@@ -138,6 +138,9 @@ input[type=checkbox] {
     margin-left: 20px;
 }
 
+.x-error {
+    color:red;
+}
 
 /*layout-up-down:上下布局模式*/
 .wp-json .mod-json.layout-up-down {

+ 1 - 1
apps/json-format/index.html

@@ -31,7 +31,7 @@
                         <button id="btnFormat" class="btn btn-primary" @click="format">格式化</button>
                         <button id="btnCompress" class="btn btn-success" @click="compress">压缩</button>
                         <input type="checkbox" v-model="jsonLintSwitch" id="jsonLint" @click="lintOn"><label for="jsonLint">开启JSONLint</label>
-                        <input type="checkbox" v-model="overrideJson" id="jsonOvrd"><label for="jsonOvrd">点选JSON项时默认进行编辑</label>
+                        <input type="checkbox" v-model="overrideJson" id="jsonOvrd" @click="setCache"><label for="jsonOvrd">点选JSON项时默认进行编辑</label>
                     </div>
                     <div id="errorTips" v-bind:style="{display:showTips?'block':'none'}">
                         <div id="errorBtn" @click="closeTips"><span id="closeError">☓</span></div>

+ 29 - 8
apps/json-format/index.js

@@ -3,6 +3,8 @@
  */
 let editor = {};
 let LOCAL_KEY_OF_LAYOUT = 'local-layout-key';
+let JSON_LINT = 'jsonformat:json-lint-switch';
+let EDIT_ON_CLICK = 'jsonformat:edit-on-click';
 
 // json with bigint supported
 Tarp.require('../static/vendor/json-bigint/index');
@@ -26,6 +28,8 @@ new Vue({
     mounted: function () {
         this.resultContent = this.defaultResultTpl;
 
+        this.jsonLintSwitch = (localStorage.getItem(JSON_LINT) !== 'false');
+        this.overrideJson = (localStorage.getItem(EDIT_ON_CLICK) === 'true');
         this.changeLayout(localStorage.getItem(LOCAL_KEY_OF_LAYOUT));
 
         editor = CodeMirror.fromTextArea(this.$refs.jsonBox, {
@@ -93,13 +97,17 @@ new Vue({
                 // new Function的方式,能自动给key补全双引号,但是不支持bigint,所以是下下策,放在try-catch里搞
                 try {
                     jsonObj = new Function("return " + source)();
-                    // 还要防止下面这种情况:  "{\"ret\":\"0\", \"msg\":\"ok\"}"
-                    if (typeof jsonObj === "string") {
-                        // 再来一次
-                        jsonObj = new Function("return " + jsonObj)();
-                    }
                 } catch (exx) {
-                    this.errorMsg = ex.message;
+                    try {
+                        // 再给你一次机会,是不是下面这种情况:  "{\"ret\":\"0\", \"msg\":\"ok\"}"
+                        jsonObj = new Function("return '" + source + "'")();
+                        if (typeof jsonObj === 'string') {
+                            // 最后给你一次机会,是个字符串,老夫给你再转一次
+                            jsonObj = new Function("return " + jsonObj)();
+                        }
+                    } catch (exxx) {
+                        this.errorMsg = exxx.message;
+                    }
                 }
             }
 
@@ -130,9 +138,13 @@ new Vue({
             }
 
             if (this.errorMsg.length) {
-                return this.lintOn();
+                if (this.jsonLintSwitch) {
+                    return this.lintOn();
+                } else {
+                    this.resultContent = '<span class="x-error">' + this.errorMsg + '</span>';
+                    return true;
+                }
             }
-            return true;
         },
 
         compress: function () {
@@ -161,7 +173,16 @@ new Vue({
             localStorage.setItem(LOCAL_KEY_OF_LAYOUT, type);
         },
 
+        setCache: function () {
+            this.$nextTick(() => {
+                localStorage.setItem(EDIT_ON_CLICK, this.overrideJson);
+            });
+        },
+
         lintOn: function () {
+            this.$nextTick(() => {
+                localStorage.setItem(JSON_LINT, this.jsonLintSwitch);
+            });
             if (!editor.getValue().trim()) {
                 return true;
             }

+ 9 - 2
apps/manifest.json

@@ -1,9 +1,9 @@
 {
   "name": "WEB前端助手(FeHelper)",
-  "version": "2018.05.2212",
+  "version": "2018.05.2515",
   "manifest_version": 2,
   "default_locale": "zh_CN",
-  "description": "FE助手:包括JSON格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页转为图片、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试",
+  "description": "FE助手:包括JSON格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页滚动截屏、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试",
   "icons": {
     "16": "static/img/fe-16.png",
     "48": "static/img/fe-48.png",
@@ -33,6 +33,13 @@
     "<all_urls>"
   ],
   "optional_permissions": ["downloads"],
+  "commands": {
+    "_execute_browser_action": {
+      "suggested_key": {
+        "default": "Alt+Shift+F"
+      }
+    }
+  },
   "web_accessible_resources": [
     "static/img/fe-16.png",
     "static/img/fe-48.png",

文件差異過大導致無法顯示
+ 0 - 0
apps/options/index.html


+ 1 - 1
apps/page-capture/index.html

@@ -14,7 +14,7 @@
         <div class="panel-heading">
             <h3 class="panel-title">
                 <a href="http://www.baidufe.com/fehelper/feedback.html" target="_blank" class="x-a-high">
-                    <img src="../static/img/fe-16.png" alt="fehelper"/> FeHelper</a>:截预览
+                    <img src="../static/img/fe-16.png" alt="fehelper"/> FeHelper</a>:截预览
                 <input id="btnSave" class="btn btn-success btn-sm ui-fl-r" type="button" value="保存图片到本地" @click="save">
             </h3>
         </div>

文件差異過大導致無法顯示
+ 0 - 0
apps/popup/index.html


部分文件因文件數量過多而無法顯示