atcoder-keyboard-shortcuts

atcoder keyboard shortcuts

当前为 2020-03-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name atcoder-keyboard-shortcuts
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description atcoder keyboard shortcuts
  6. // @author springroll
  7. // @match https://atcoder.jp/contests/*/tasks/*
  8. // @require https://unpkg.com/hotkeys-js/dist/hotkeys.min.js
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. var copySample = function(index) {
  14. window.getSelection().removeAllRanges();
  15. try {
  16. var range = document.createRange();
  17. range.selectNode($('#pre-sample'+(2*(index-1))).get(0));
  18. window.getSelection().addRange(range);
  19. document.execCommand('copy');
  20. } catch (err) {
  21. console.log(err);
  22. }
  23. alert("Copied Sample" + index + ".");
  24. window.getSelection().removeAllRanges();
  25. }
  26. hotkeys('shift+1,shift+2,shift+3,shift+4,shift+5', function (event, handler){
  27. switch (handler.key) {
  28. case 'shift+1':
  29. copySample(1);
  30. break;
  31. case 'shift+2':
  32. copySample(2);
  33. break;
  34. case 'shift+3':
  35. copySample(3);
  36. break;
  37. case 'shift+4':
  38. copySample(4);
  39. break;
  40. case 'shift+5':
  41. copySample(5);
  42. break;
  43. default: alert(event);
  44. }
  45. });
  46.  
  47. })();