Bläddra i källkod

自动格式化后支持数据下载

Alien 11 år sedan
förälder
incheckning
4403e7a6db

+ 1 - 1
chrome/manifest.json

@@ -1,6 +1,6 @@
 { 
 	"name": "WEB前端助手(FeHelper)", 
-	"version": "5.6",
+	"version": "5.7",
     "manifest_version": 2,
 	 
 	"default_locale": "zh_CN", 

+ 1 - 1
chrome/online.manifest.json

@@ -1,6 +1,6 @@
 {
     "name": "WEB前端助手(FeHelper)",
-    "version": "5.6",
+    "version": "5.7",
     "manifest_version": 2,
 
     "default_locale": "zh_CN",

+ 10 - 3
chrome/static/css/fe-jsonformat.css

@@ -1,13 +1,20 @@
 #jfContent{-webkit-user-select:text;margin:0;}
 #optionBar{-webkit-user-select:none;display:block;position:absolute;top:0px;right:0px}
-#buttonFormatted,#buttonPlain{-webkit-border-radius:2px;-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.1);
+#buttonFormatted,#buttonPlain,#btnDownload{-webkit-border-radius:2px;-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.1);
 	-webkit-user-select:none;background:-webkit-linear-gradient(#fafafa, #f4f4f4 40%, #e5e5e5);
 	border:1px solid #aaa;color:#444;font-size:12px;margin-bottom:0px;min-width:4em;padding:3px 0;
 	position:relative;z-index:10;display:inline-block;width:80px;
 	text-shadow:1px 1px rgba(255,255,255,0.3)}
 #buttonFormatted{margin-left:0;border-top-left-radius:0;border-bottom-left-radius:0}
 #buttonPlain{margin-right:0;border-top-right-radius:0;border-bottom-right-radius:0;border-right:none}
-#buttonFormatted:hover,#buttonPlain:hover{-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.2);
+#btnDownload {
+    padding: 4px 10px;
+    text-decoration: none;
+    color: #454545;
+    margin-right: 10px;
+    display: inline-block;
+}
+#buttonFormatted:hover,#buttonPlain:hover,#btnDownload:hover{-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.2);
 	background:#ebebeb -webkit-linear-gradient(#fefefe, #f8f8f8 40%, #e9e9e9);border-color:#999;color:#222}
 #buttonFormatted:active,#buttonPlain:active{-webkit-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.2);
 	background:#ebebeb -webkit-linear-gradient(#f4f4f4, #efefef 40%, #dcdcdc);color:#333}
@@ -133,4 +140,4 @@ html body {
 #jfContent .x-outline {
     outline:1px solid #6ac;
     background: #f9f9f9;
-}
+}

+ 35 - 1
chrome/static/js/jsonformat/contentscript-jsonformat.js

@@ -152,12 +152,46 @@ baidu.csJsonFormat = (function () {
                 $('#jfCallbackName_start').html(funcName + '(');
                 $('#jfCallbackName_end').html(')');
             }
+
+            // 支持数据下载
+            _downloadJsonFile(jsonObj);
+        }
+    };
+
+    /**
+     * 下载数据
+     * @param json
+     * @private
+     */
+    var _downloadJsonFile = function (json) {
+        try {
+            window.webkitRequestFileSystem(window.TEMPORARY, 10 * 1024 * 1024, function (fs) {
+                var dir = (+new Date).toString(36);
+                var name = +new Date() + '.json';
+                fs.root.getDirectory(dir, {create:true}, function (dirEntry) {
+                    var file = dir + '/' + name;
+                    fs.root.getFile(file, {create:true}, function (fileEntry) {
+                        fileEntry.createWriter(function (fileWriter) {
+                            // 数据写入完成后显示下载链接
+                            fileWriter.onwriteend = function () {
+                                $('#optionBar').prepend('<a href="' + fileEntry.toURL() + '" id="btnDownload" target="_blank" ' +
+                                    'title="在新页面Ctrl+S保存到本地">下载JSON数据</a>');
+                            };
+                            var blob = new Blob([JSON.stringify(json, null, 8) ], {type:'application/octet-stream'});
+                            fileWriter.write(blob);
+                        });
+                    });
+                });
+            });
+        } catch (e) {
         }
     };
 
     var _init = function () {
         $(function () {
-            _format();
+            if (!/^filesystem\:/.test(location.href)) {
+                _format();
+            }
         });
     };