load_shortcut.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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 doc_shortcut = /^\/(w|history)\//i;
  7. shortcut_key_list[e.key] = 1;
  8. if(
  9. window.location.pathname.match(doc_shortcut) ||
  10. window.location.pathname === '/recent_change' ||
  11. window.location.pathname === '/recent_changes' ||
  12. window.location.pathname === '/recent_discuss'
  13. ) {
  14. if(shortcut_key_list['f'] === 1) {
  15. window.location.href = '/';
  16. } else if(shortcut_key_list['c'] === 1) {
  17. window.location.href = '/recent_change';
  18. } else if(shortcut_key_list['d'] === 1) {
  19. window.location.href = '/recent_discuss';
  20. } else if(shortcut_key_list['a'] === 1) {
  21. window.location.href = '/random';
  22. }
  23. }
  24. if(window.location.pathname.match(doc_shortcut)) {
  25. if(shortcut_key_list['w'] === 1) {
  26. window.location.pathname = window.location.pathname.replace(doc_shortcut, '/w/');
  27. } else if(shortcut_key_list['e'] === 1) {
  28. window.location.pathname = window.location.pathname.replace(doc_shortcut, '/edit/');
  29. } else if(shortcut_key_list['h'] === 1) {
  30. window.location.pathname = window.location.pathname.replace(doc_shortcut, '/history/');
  31. }
  32. }
  33. }