Vimfari

try to take over the world!

  1. // ==UserScript==
  2. // @name Vimfari
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Settings
  15. var setings = {
  16. 'j': 'scrollDown',
  17. 'k': 'scrollUp',
  18. 'gg': 'scrollToTop',
  19. 'G': 'scrollToBottom',
  20. 'u': 'scrollPageUp',
  21. 'd': 'scrollPageDown'
  22. };
  23.  
  24. // Methods
  25. window.scrollDown = function () {
  26. var yPos = $(window).scrollTop();
  27. $('html, body').animate({ scrollTop: yPos + 300 }, 150);
  28. };
  29. window.scrollUp = function () {
  30. var yPos = $(window).scrollTop();
  31. $('html, body').animate({ scrollTop: yPos - 300 }, 150);
  32. };
  33. window.scrollToTop = function () {
  34. $("html, body").animate({ scrollTop: 0 }, 200);
  35. };
  36. window.scrollToBottom = function () {
  37. $("html, body").animate({ scrollTop: $(document).height() }, 200);
  38. };
  39. window.scrollPageDown = function () {
  40. var yPos = $(window).scrollTop();
  41. $("html, body").animate({ scrollTop: yPos + $(window).height() }, 150);
  42. };
  43. window.scrollPageUp = function () {
  44. var yPos = $(window).scrollTop();
  45. $("html, body").animate({ scrollTop: yPos - $(window).height() }, 150);
  46. };
  47.  
  48. // Remove AutoFocus at the first time
  49. $('input').blur();
  50.  
  51.  
  52. // Controllers
  53. var timing = 500;
  54. var lastKeypressTime = 0;
  55. var prevKey = '';
  56.  
  57. $('html').keypress(function(e) {
  58. var unicode = e.keyCode? e.keyCode : e.charCode;
  59. var key = String.fromCharCode(unicode);
  60.  
  61. // Detect the double key press
  62. var thisKeypressTime = new Date();
  63. if ( thisKeypressTime - lastKeypressTime <= timing ) {
  64. key = prevKey + key;
  65. thisKeypressTime = 0;
  66. }
  67. lastKeypressTime = thisKeypressTime;
  68.  
  69. var fn = window[setings[key]];
  70.  
  71. if(typeof fn === 'function') {
  72. fn();
  73. }
  74.  
  75. console.log(key + " : " + unicode);
  76. prevKey = key;
  77. });
  78.  
  79. })();