浏览代码

优化JSON自动格式化的性能

zxlie 6 年之前
父节点
当前提交
8013230a0d
共有 3 个文件被更改,包括 7 次插入5 次删除
  1. 6 4
      apps/json-format/automatic.js
  2. 1 1
      apps/manifest.json
  3. 二进制
      apps/static/screenshot/crx/WEB前端助手(FeHelper)_v2019.09.0320.crx

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

@@ -35,9 +35,10 @@ module.exports = (() => {
     let _getJsonText = function () {
 
         let pre = $('body>pre:eq(0)')[0] || {textContent: ""};
-        let source = $.trim(pre.textContent);
+        let source = pre.textContent.trim();
+
         if (!source) {
-            source = $.trim(document.body.textContent || '')
+            source = (document.body.textContent || '').trim()
         }
         if (!source) {
             return false;
@@ -48,11 +49,12 @@ module.exports = (() => {
         let nodes = document.body.childNodes;
         let newSource = '';
         for (let i = 0, len = nodes.length; i < len; i++) {
+
             if (nodes[i].nodeType === Node.TEXT_NODE) {
                 newSource += nodes[i].textContent;
             } else if (nodes[i].nodeType === Node.ELEMENT_NODE) {
                 let tagName = nodes[i].tagName.toLowerCase();
-                let html = $.trim(nodes[i].textContent);
+                let html = (nodes[i].textContent || '').trim();
                 // 如果是pre标签,则看内容是不是和source一样,一样则continue
                 if (tagName === 'pre' && html === source) {
                 } else if ((nodes[i].offsetWidth === 0 || nodes[i].offsetHeight === 0 || !html) && ['script', 'link'].indexOf(tagName) === -1) {
@@ -65,7 +67,7 @@ module.exports = (() => {
             }
         }
 
-        return $.trim(newSource || '') || source;
+        return (newSource || '').trim() || source;
     };
 
     /**

+ 1 - 1
apps/manifest.json

@@ -1,6 +1,6 @@
 {
   "name": "WEB前端助手(FeHelper)-Dev",
-  "version": "2019.09.0315",
+  "version": "2019.09.0320",
   "manifest_version": 2,
   "default_locale": "zh_CN",
   "description": "Awesome,All In One的一个工具,包含多个独立小应用,比如:Json工具、代码美化、代码压缩、二维码、Postman、markdown、网页油猴、便签笔记、信息加密与解密、随机密码生成、Crontab等等!",

二进制
apps/static/screenshot/crx/WEB前端助手(FeHelper)_v2019.09.0320.crx