os0x (owner)

Fork Of

gist: 121142 by taizooo ref http://userscripts.org/...

Revisions

gist: 121296 Download_button fork
public
Public Clone URL: git://gist.github.com/121296.git
Embed All Files: show embed
scrollcommand.user.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// ==UserScript==
// @name ScrollCommand
// @namespace http://d.hatena.ne.jp/Constellation/
// @description Press j or k key , and scroll (in case that LDRize are not working on its page)
// @include *
// @exclude http://www.google.tld/reader/*
// @exclude https://www.google.tld/reader/*
// @exclude http://mail.google.tld/*
// @exclude https://mail.google.tld/*
// @author Constellation
// @version 0.0.3
// ==/UserScript==
 
function boot(ev){
  if(ev) window.removeEventListener('GM_MinibufferLoaded', boot, false);
 
  if (!window.Minibuffer) return;
 
  //=========[Config]==================
 
  var SCROLLHEIGHT = 200;
  var TIME = 100;
 
  //=========[Application]=============
 
  var Class = function(){return function(){this.initialize.apply(this,arguments)}};
  var Scroll = new Class();
 
  Scroll.prototype = {
    initialize : function(down){
      this.down = down;
      this.i = 0;
      this.height = 0;
      this.active = true;
      this.go();
    },
    go : function(){
      if(!(Scroll.down == this.down) && !this.i==0) return this.cancel();
      var self = this;
      var height = Scroll.h[this.i++];
      var value = height - self.height;
      self.height = height;
      if(!self.down) value = -(value);
      window.scrollBy(0, value);
      var f = function(){self.go.call(self)};
      if(this.i < 10) this.scl = setTimeout(f, Scroll.delay);
      else this.active = false;
    },
    cancel : function(){
      if(this.enable){
        clearTimeout(this.scl);
        this.active = false;
      }
    }
  }
 
  Scroll.set = function(){
    Scroll.enable = true;
    var t = [];
    for (var i = 0;i < 10;i++){
      var a = i+1;
      t[i] = Math.round(SCROLLHEIGHT * (Math.sin(Math.PI * a / 20)));
    }
    Scroll.h = t;
    Scroll.delay = Math.round(TIME / 9);
  }
  Scroll.enable = false;
 
  [
    {
    key:'S-SPC',
    description: 'scrollcommand::prev',
    command: function(){
      if(!Scroll.enable) Scroll.set();
      Scroll.down = false;
      var scroll = new Scroll(false);
    }
    },
    {
    key:'SPC',
    description: 'scrollcommand::next',
    command: function(){
      if(!Scroll.enable) Scroll.set();
      Scroll.down = true;
      var scroll = new Scroll(true);
    }
    }
  ]
  .forEach(window.Minibuffer.addShortcutkey);
 
  if (window.LDRize && window.LDRize.getSiteinfo() == undefined) {
  [
    {
    key:'j',
    description: 'scrollcommand::next',
    command: function(){
      if(!Scroll.enable) Scroll.set();
      Scroll.down = true;
      var scroll = new Scroll(true);
    }
    },
    {
    key:'k',
    description: 'scrollcommand::prev',
    command: function(){
      if(!Scroll.enable) Scroll.set();
      Scroll.down = false;
      var scroll = new Scroll(false);
    }
    }
  ]
  .forEach(window.Minibuffer.addShortcutkey);
  }
}
 
if(window.Minibuffer){
  boot();
} else {
  window.addEventListener('GM_MinibufferLoaded', boot, false);
}