Browse Source

增加功能:页面屏幕标尺

zxlie 6 năm trước cách đây
mục cha
commit
e703dc7c65

+ 1 - 0
README.md

@@ -42,6 +42,7 @@ https://chrome.google.com/webstore/detail/pkgccpejnmalmdinmhkkfafefagiiiad?hl=zh
 - 随机密码生成(任意字符、任意长度、随机生成)
 - 编码规范检测(HTML/CSS/JS规范检测)
 - 页面性能检测(页面响应时间、Header监测)
+- 页面栅格标尺(页面栅格化、屏幕标尺)
 - Ajax调试功能(需在控制台中使用)
 - 网页编码设置(UTF-8、GBK、日文、韩文等)
 - 我的便签笔记(便签笔记,支持导出)

+ 17 - 0
apps/background/index.js

@@ -235,6 +235,15 @@ var BgPageInstance = (function () {
         });
     };
 
+    /**
+     * 屏幕栅格标尺
+     */
+    let _doGridDetect = function(tab){
+        chrome.tabs.sendMessage(tab.id, {
+            type : MSG_TYPE.GRID_RULER
+        });
+    };
+
     /**
      * 根据给定参数,运行对应的Helper
      */
@@ -265,6 +274,10 @@ var BgPageInstance = (function () {
                     case MSG_TYPE.AJAX_DEBUGGER:
                         _debuggerSwitchOn(callback);
                         break;
+                    // 屏幕栅格标尺
+                    case MSG_TYPE.GRID_RULER:
+                        _doGridDetect(tab);
+                        break;
                     default :
                         break;
                 }
@@ -378,6 +391,9 @@ var BgPageInstance = (function () {
                     },
                     MENU_STICKY_NOTE: function (info, tab) {
                         _openFileAndRun(tab, MSG_TYPE.STICKY_NOTES);
+                    },
+                    MENU_GRID_RULER: function(info,tab){
+                        _doGridDetect(tab);
                     }
                 };
 
@@ -650,6 +666,7 @@ var BgPageInstance = (function () {
                 chrome.runtime.openOptionsPage();
             }
 
+
             // ===========================以下为编码规范检测====start==================================
             //处理CSS的请求
             else if (request.type === MSG_TYPE.GET_CSS) {

+ 5 - 0
apps/content-script/index.js

@@ -80,6 +80,11 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
                 }
             });
             break;
+
+        // 屏幕栅格标尺
+        case MSG_TYPE.GRID_RULER:
+            Tarp.require('../ruler/index',true).then(ruler => ruler.detect(callback));
+            break;
     }
 
 });

+ 4 - 2
apps/manifest.json

@@ -1,6 +1,6 @@
 {
   "name": "WEB前端助手(FeHelper)",
-  "version": "2018.12.1412",
+  "version": "2018.12.1417",
   "manifest_version": 2,
   "default_locale": "zh_CN",
   "description": "FE助手:包括JSON格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页滚动截屏、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试、密码生成器、JSON比对工具、网页编码设置、便签笔记",
@@ -82,7 +82,9 @@
     "static/vendor/jquery/jquery.extend.js",
     "static/vendor/json-bigint/index.js",
     "static/vendor/prism/prism.js",
-    "static/vendor/prism/prism.css"
+    "static/vendor/prism/prism.css",
+    "ruler/index.js",
+    "ruler/index.css"
   ],
   "content_scripts": [
     {

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
apps/options/index.html


+ 6 - 1
apps/options/settings.js

@@ -33,7 +33,8 @@ module.exports = (() => {
         'FORBID_OPEN_IN_NEW_TAB',
         'MAX_JSON_KEYS_NUMBER',
         'AUTO_TEXT_DECODE',
-        'STICKY_NOTES'
+        'STICKY_NOTES',
+        'GRID_RULER'
     ];
 
     // 邮件菜单配置项
@@ -120,6 +121,10 @@ module.exports = (() => {
         MENU_STICKY_NOTE: {
             icon: '▤',
             text: '我的便签笔记'
+        },
+        MENU_GRID_RULER: {
+            icon: '✚',
+            text: '页面栅格标尺'
         }
     };
 

+ 3 - 0
apps/popup/index.css

@@ -151,6 +151,9 @@ ul.fe-function-list li.-x-jsondiff b {
 ul.fe-function-list li.-x-sticky-notes b {
     background-position: -65px -96px;
 }
+ul.fe-function-list li.-x-grid-ruler b {
+    background-position: -33px -127px;
+}
 
 
 ul.fe-function-list li i {

+ 2 - 0
apps/popup/index.html

@@ -41,6 +41,8 @@
                     <b></b>编码规范检测</li>
                 <li class="-x-loadtime" @click="runHelper('SHOW_PAGE_LOAD_TIME',0)" v-if="canMeShow.SHOW_PAGE_LOAD_TIME">
                     <b></b>页面性能检测</li>
+                <li class="-x-grid-ruler" @click="runHelper('GRID_RULER',0)" v-if="canMeShow.GRID_RULER">
+                    <b></b>页面栅格标尺</li>
                 <li class="-x-ajax-debugger" title="在开发者工具-Console面板使用" @click="runHelper('AJAX_DEBUGGER',0)" v-if="canMeShow.AJAX_DEBUGGER">
                     <b></b>Ajax调试:<i>{{ ajaxDebugger }}</i></li>
                 <li class="-x-sticky-notes" @click="runHelper('STICKY_NOTES',1)" v-if="canMeShow.STICKY_NOTES">

+ 97 - 0
apps/ruler/index.css

@@ -0,0 +1,97 @@
+#fe-helper-box {
+    position: fixed;
+    left: 1px;
+    bottom: 0;
+    right:8px;
+    z-index: 2147483646;
+    font-size:12px;
+}
+#fe-helper-grid {
+    position:fixed;
+    top:0;
+    left:0;
+    z-index:2147483647;
+    opacity:0.03;
+    overflow:hidden;
+    -webkit-user-select:none;
+    background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAANElEQVQYGWP8Jij7n4EIwPnuERGqGBiYwKrQjUTnE2UURBHEQEYGBgZkQ0B8EEAWgwoRogAZUQgA7keT1AAAAABJRU5ErkJggg==) repeat;
+}
+#fe-helper-btn-close-grid {
+    position:fixed;
+    bottom:10px;
+    right:10px;
+    font-size:12px;
+    font-weight:bold;
+    color:#00f;
+    z-index:2147483647;
+    cursor:pointer;
+}
+#fe-helper-btn-close-grid:hover {
+    color:#f00;
+}
+#fe-helper-g-pos {
+    background:none;
+    position:absolute;
+    top:0;
+    left:0;
+    z-index:2147483646;
+    border:1px solid #0b0;
+    border-width:0 1px 1px 0;
+}
+#fe-helper-gp-info {
+    position:absolute;
+    z-index:2147483646;
+    background:#ffc;
+    border:1px solid #666;
+    font-size:12px;
+    text-align:left;
+    padding:2px 10px;
+    display:none;
+    color:#000;
+}
+#fe-helper-ruler-top {
+    position:fixed;
+    top:0;
+    left:0;
+    right:0;
+    height:30px;
+    background:#fc0;
+    border-bottom:1px solid #000;
+    z-index:2147483647;
+    overflow:hidden;
+}
+#fe-helper-ruler-left {
+    position:fixed;
+    top:0;
+    left:0;
+    bottom:0;
+    width:30px;
+    background:#fc0;
+    border-right:1px solid #000;
+    z-index:2147483647;
+    overflow:hidden;
+}
+#fe-helper-ruler-top .h-line{
+    position:absolute;
+    width:1px;
+    background:#000;
+}
+#fe-helper-ruler-top .h-text{
+    position:absolute;
+    top:0;
+    font-size:8px;
+    color:#000;
+}
+#fe-helper-ruler-left .v-line{
+    position:absolute;
+    height:1px;
+    background:#000;
+}
+#fe-helper-ruler-left .v-text{
+    position:absolute;
+    left:0;
+    font-size:8px;
+    color:#000;
+    -webkit-transform:rotate(90deg);
+    margin-top:4px;
+}

+ 188 - 0
apps/ruler/index.js

@@ -0,0 +1,188 @@
+/**
+ * 栅格相关处理
+ * @author zhaoxianlie
+ */
+let GridRuler = (function () {
+
+    // 加载CSS
+    let _loadCss = function () {
+        if (!jQuery('#_fehelper_grid_css_')[0]) {
+            let cssUrl = chrome.extension.getURL('ruler/index.css');
+            jQuery('<link id="_fehelper_grid_css_" href="' + cssUrl + '" rel="stylesheet" type="text/css" />').appendTo('head');
+        }
+    };
+
+    // 创建栅格
+    let _createGrid = function () {
+
+        let box = jQuery('#fe-helper-box');
+        if (box[0]) {	//已经有栅格,则移除
+            box.remove();
+        }
+        //没有栅格,则创建
+        let $win = jQuery(window);
+        let $body = jQuery('body');
+        jQuery('<div id="fe-helper-box"></div>').appendTo('body').css({
+            position: 'static'
+        });
+        jQuery('<div id="fe-helper-grid"></div>').appendTo('#fe-helper-box').css({
+            width: $body.width(),
+            height: Math.max($win.height(), $body.height())
+        }).mousemove(function (e) {
+            let pos = {};
+            try {
+                pos = document.getElementsByTagName('body')[0].getBoundingClientRect();
+            } catch (err) {
+                pos = {left: 0, top: 0};
+            }
+            //虚线框
+            jQuery('#fe-helper-g-pos').show().css({
+                width: e.pageX - pos.left,
+                height: e.pageY
+            });
+
+            let _t = Math.min(e.pageY, jQuery(window).height() + $body.scrollTop() - 40);
+            let _l = Math.min(e.pageX, jQuery(window).width() + $body.scrollLeft() - 200) + 5 - pos.left;
+
+            //坐标tooltip
+            jQuery('#fe-helper-gp-info').show().css({
+                top: _t,
+                left: _l
+            }).html('top = ' + e.pageY + ' px ,left = ' + e.pageX + ' px');
+        }).mouseout(function (e) {
+            jQuery('#fe-helper-g-pos,#fe-helper-gp-info').hide();
+        });
+
+        jQuery('<div id="fe-helper-g-pos"></div><div id="fe-helper-gp-info"></div>').appendTo('#fe-helper-box');
+        jQuery('<span id="fe-helper-btn-close-grid">关闭栅格层</span>')
+            .appendTo('#fe-helper-box').click(function () {
+            jQuery('#fe-helper-box').remove();
+        });
+    };
+
+    // 绘制Ruler
+    let _drawRuler = function () {
+
+        let _t = 0, _h = 30, _w = 30;
+        let $win = jQuery(window);
+        let $page = jQuery('html');
+        let elScroll = jQuery(document.scrollingElement || 'html');
+        let $width = Math.max($win.width(), $page.width(), elScroll[0].scrollWidth);
+        let $height = Math.max($win.height(), $page.height(), elScroll[0].scrollHeight);
+        let rulerTop = jQuery('#fe-helper-ruler-top').width($width);
+        let rulerLeft = jQuery('#fe-helper-ruler-left').height($height);
+
+        if (!rulerTop.children().length || rulerTop.children().last().position().left < $width - 50) {
+            rulerTop.html('');
+            for (let i = 30; i <= $width; i += 10) {
+                _t = (i % 50) ? 10 : 0;
+                jQuery('<div class="h-line"></div>').appendTo('#fe-helper-ruler-top').css({
+                    left: i - 1,
+                    top: _t + 15,
+                    height: _h - _t - 5
+                });
+                if (_t === 0 && i !== 0) {
+                    jQuery('<div class="h-text">' + i + '</div>').appendTo('#fe-helper-ruler-top').css({
+                        left: i - (String(i).length * 4)
+                    });
+                }
+            }
+        }
+
+        if (!rulerLeft.children().length || rulerLeft.children().last().position().top < $height - 50) {
+            rulerLeft.html('');
+            for (let i = 0; i <= $height; i += 10) {
+                _l = (i % 50) ? 10 : 0;
+                jQuery('<div class="v-line"></div>').appendTo('#fe-helper-ruler-left').css({
+                    left: _l + 15,
+                    top: i - 1,
+                    width: _w - _l - 5
+                });
+                if (_l === 0) {
+                    jQuery('<div class="v-text">' + i + '</div>').appendTo('#fe-helper-ruler-left').css({
+                        top: i - (String(i).length * 4),
+                        left: i === 0 ? 5 : 0
+                    });
+                }
+            }
+        }
+    };
+
+    // 创建页面标尺
+    let _createPageRuler = function () {
+        if (!jQuery('#fe-helper-box')[0]) {
+            jQuery('<div id="fe-helper-box"></div>').appendTo('body');
+        }
+        jQuery('<div id="fe-helper-ruler-top"></div><div id="fe-helper-ruler-left"></div>').appendTo('#fe-helper-box');
+        _drawRuler();
+
+    };
+
+    // 全局事件绑定
+    let _bindEvent = function () {
+
+        //为页面注册按键监听
+        jQuery('body').keydown(function (e) {
+            if (jQuery('#fe-helper-box')[0]) {
+                if (e.which === 27) { //ESC
+                    jQuery('#fe-helper-box').remove();
+                }
+            }
+        });
+
+        //window.onresize
+        jQuery(window).resize(function () {
+            if (jQuery('#fe-helper-box')[0]) {
+                let $win = jQuery(window);
+                let $body = jQuery('body');
+                jQuery('#fe-helper-grid').css({
+                    width: Math.max($win.width(), $body.width()),
+                    height: Math.max($win.height(), $body.height())
+                });
+
+                _drawRuler();
+            }
+        });
+
+        //处理scroll的时候,标尺跟着移动
+        jQuery(window).scroll(function (e) {
+            if (jQuery('#fe-helper-box')[0]) {
+                let elScroll = jQuery(document.scrollingElement || 'html');
+                //水平标尺定位
+                jQuery('#fe-helper-ruler-top').css('left', 0 - elScroll.scrollLeft());
+                //垂直标尺
+                jQuery('#fe-helper-ruler-left').css('top', 0 - elScroll.scrollTop());
+            }
+        });
+    };
+
+    /**
+     * 执行栅格系统检测
+     */
+    let _detect = function (callback) {
+
+        // 加载CSS
+        _loadCss();
+
+        //创建栅格
+        _createGrid();
+
+        //创建页面标尺
+        _createPageRuler();
+
+        // 事件绑定
+        _bindEvent();
+
+
+        //执行回调
+        if (callback && typeof callback === "function") {
+            callback.call(null);
+        }
+    };
+
+    return {
+        detect: _detect
+    };
+})();
+
+module.exports = GridRuler;

+ 4 - 1
apps/static/js/msg_type.js

@@ -101,7 +101,10 @@ const MSG_TYPE = {
     // dev tools页面
     DEV_TOOLS: 'dev-tools',
 
-    OPEN_OPTIONS_PAGE:'open-options-page'
+    OPEN_OPTIONS_PAGE:'open-options-page',
+
+    // 屏幕栅格标尺
+    GRID_RULER: 'grid-ruler'
 };
 
 (typeof module === 'object') ? module.exports = MSG_TYPE : '';

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác