Pārlūkot izejas kodu

增加快捷键配置

zxlie 6 gadi atpakaļ
vecāks
revīzija
83b2d0472c

+ 1 - 1
apps/manifest.json

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

+ 14 - 0
apps/options/index.css

@@ -114,4 +114,18 @@ h5,h4 {
     background-color: #276cf9;
     color: #fff;
     cursor: default;
+}
+#setShortcuts {
+    font-size: 14px;
+    text-decoration: underline;
+    color: #666;
+    display: inline-block;
+    margin-bottom: 5px;
+}
+#setShortcuts:hover {
+    color:#f00;
+}
+.x-tips {
+    font-size: 12px;
+    color: #aaa;
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
apps/options/index.html


+ 18 - 0
apps/options/index.js

@@ -7,6 +7,7 @@ let Settings = Tarp.require('./settings');
 new Vue({
     el: '#pageContainer',
     data: {
+        defaultKey: 'Alt+Shift+F',
         selectedOpts: [],
         maxJsonKeysNumber: 0,
         auto_text_decode: false,
@@ -18,6 +19,16 @@ new Vue({
 
     created: function () {
 
+        // 获取当前热键
+        chrome.commands && chrome.commands.getAll && chrome.commands.getAll(keys => {
+            keys.some(key => {
+                if (key.name === '_execute_browser_action' && key.shortcut) {
+                    this.defaultKey = key.shortcut;
+                    return true;
+                }
+            });
+        });
+
         Settings.getOptions((opts) => {
             this.selectedOpts = Object.keys(opts).filter(k => {
                 if (typeof(opts[k]) === 'string' && /^MENU_/.test(k)) {
@@ -63,6 +74,13 @@ new Vue({
             setTimeout(() => {
                 this.close();
             }, 1000);
+        },
+
+        setShortcuts: function () {
+            chrome.tabs.create({
+                url: 'chrome://extensions/shortcuts'
+            });
+            return false;
         }
     }
 });

+ 1 - 0
apps/popup/index.css

@@ -51,6 +51,7 @@ ul.fe-function-list li:last-child {
     border-bottom: none;
 }
 
+ul.fe-function-list li.x-hovered,
 ul.fe-function-list li:hover {
     color: #ff3C11;
     background: #f1f1f1;

+ 37 - 0
apps/popup/index.js

@@ -26,6 +26,43 @@ new Vue({
         });
     },
 
+    mounted: function () {
+
+        // 整个popup窗口支持上线选择
+        document.body.addEventListener('keydown', e => {
+            let keyCode = e.keyCode || e.which;
+            if(![38,40,13].includes(keyCode)) {
+                return false;
+            }
+            let ul = document.querySelector('#pageContainer ul');
+            let hovered = ul.querySelector('li.x-hovered');
+            let next,prev;
+            if (hovered) {
+                hovered.classList.remove('x-hovered');
+                next = hovered.nextElementSibling;
+                prev = hovered.previousElementSibling;
+            }
+            if (!next) {
+                next = ul.querySelector('li:first-child');
+            }
+            if(!prev) {
+                prev = ul.querySelector('li:last-child');
+            }
+
+            switch (keyCode) {
+                case 38: // 方向键:↑
+                    prev.classList.add('x-hovered');
+                    break;
+                case 40: // 方向键:↓
+                    next.classList.add('x-hovered');
+                    break;
+                case 13: // 回车键:选择
+                    hovered.click();
+            }
+
+        }, false);
+    },
+
     methods: {
 
         runHelper: function (mType, useFile) {

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels