load_shortcut.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. let shortcut_key_list = [];
  2. document.onkeyup = function(e) {
  3. delete shortcut_key_list[e.key];
  4. }
  5. document.onkeypress = function(e) {
  6. let shortcut_check = event.target.tagName.toLowerCase();
  7. if(
  8. shortcut_check !== 'input' &&
  9. shortcut_check !== 'textarea'
  10. ) {
  11. let doc_shortcut = /^\/(w|history|edit|acl|topic|xref)\//i;
  12. shortcut_key_list[e.key] = 1;
  13. if(shortcut_key_list['f'] === 1) {
  14. window.location.href = '/';
  15. } else if(shortcut_key_list['c'] === 1) {
  16. window.location.href = '/recent_change';
  17. } else if(shortcut_key_list['d'] === 1) {
  18. window.location.href = '/recent_discuss';
  19. } else if(shortcut_key_list['a'] === 1) {
  20. window.location.href = '/random';
  21. }
  22. if(window.location.pathname.match(doc_shortcut)) {
  23. let doc_href = window.location.pathname.replace(doc_shortcut, '');
  24. doc_href = doc_href.replace(/%2Fdoc_from%2F(?:((?!%2F).)+)$/, '');
  25. if(shortcut_key_list['w'] === 1) {
  26. window.location.pathname = '/w/' + doc_href;
  27. } else if(shortcut_key_list['e'] === 1) {
  28. window.location.pathname = '/edit/' + doc_href;
  29. } else if(shortcut_key_list['h'] === 1) {
  30. window.location.pathname = '/history/' + doc_href;
  31. }
  32. }
  33. }
  34. }