Skip to content

Instantly share code, notes, and snippets.

@taizooo
Created June 1, 2009 02:19
Show Gist options
  • Save taizooo/121142 to your computer and use it in GitHub Desktop.
Save taizooo/121142 to your computer and use it in GitHub Desktop.
ref http://userscripts.org/scripts/show/25036 (minibuffer.use.js が"SHIFT"キーを解すようになると使えます。 http://coderepos.org/share/changeset/33693 以降)
// ==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:'k',
description: 'scrollcommand::prev',
command: function(){
if(!Scroll.enable) Scroll.set();
Scroll.down = false;
var scroll = new Scroll(false);
}
},
{
key:'j',
description: 'scrollcommand::next',
command: function(){
if(!Scroll.enable) Scroll.set();
Scroll.down = true;
var scroll = new Scroll(true);
}
}
]
.forEach(window.Minibuffer.addShortcutkey);
}
}
if(window.Minibuffer){
boot();
} else {
window.addEventListener('GM_MinibufferLoaded', boot, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment