잉여개발기 1 год назад
Родитель
Сommit
ed5ebc7f41
2 измененных файлов с 41 добавлено и 1 удалено
  1. 2 1
      route/tool/func.py
  2. 39 0
      views/main_css/js/func/shortcut.js

+ 2 - 1
route/tool/func.py

@@ -1203,7 +1203,7 @@ def skin_check(conn, set_n = 0):
         return skin
     
 def cache_v():
-    return '.cache_v285'
+    return '.cache_v286'
 
 def wiki_css(data):
     # without_DB
@@ -1236,6 +1236,7 @@ def wiki_css(data):
         data_css += '<script defer src="/views/main_css/js/func/insert_http_warning_text.js' + data_css_ver + '"></script>'
         
         data_css += '<script defer src="/views/main_css/js/func/ie_end_of_life.js' + data_css_ver + '"></script>'
+        data_css += '<script defer src="/views/main_css/js/func/shortcut.js' + data_css_ver + '"></script>'
         data_css += '<script defer src="/views/main_css/js/func/editor.js' + data_css_ver + '"></script>'
         data_css += '<script defer src="/views/main_css/js/func/render.js' + data_css_ver + '"></script>'
         

+ 39 - 0
views/main_css/js/func/shortcut.js

@@ -0,0 +1,39 @@
+"use strict";
+
+let shortcut_key_list = [];
+document.onkeyup = function(e) {
+    delete shortcut_key_list[e.key];
+}
+
+document.onkeydown = function(e) {
+    let shortcut_check = e.target.tagName.toLowerCase();
+    if(
+        shortcut_check !== 'input' &&
+        shortcut_check !== 'textarea'
+    ) {
+        let doc_shortcut = /^\/(w|w_from|history|edit|acl|topic|xref)\//i;
+
+        shortcut_key_list[e.key] = 1;
+        if(shortcut_key_list['f'] === 1) {
+            window.location.href = '/';
+        } else if(shortcut_key_list['c'] === 1) {
+            window.location.href = '/recent_change';
+        } else if(shortcut_key_list['d'] === 1) {
+            window.location.href = '/recent_discuss';
+        } else if(shortcut_key_list['a'] === 1) {
+            window.location.href = '/random';
+        }
+
+        if(window.location.pathname.match(doc_shortcut)) {
+            let doc_href = window.location.pathname.replace(doc_shortcut, '');
+            
+            if(shortcut_key_list['w'] === 1) {
+                window.location.pathname = '/w/' + doc_href;
+            } else if(shortcut_key_list['e'] === 1) {
+                window.location.pathname = '/edit/' + doc_href;
+            } else if(shortcut_key_list['h'] === 1) {
+                window.location.pathname = '/history/' + doc_href;
+            }
+        }
+    }
+}