LDRizeが無効なサイトでもj,kでスクロール by 958
概要
- LDRizeが無効のときには、"j","k"キーで上下に移動できるようにする SeaHorseスクリプト
- ついでにLDRizeが有効のときには、"S-j","S-k"キーで上下に固定量スクロールする(ver 0.02で追加)
必須拡張
- SeaHorse 1.1.1 以上
- UserAction Extension 1.0.0 以上
動作確認環境
- Windows XP SP2
- Internet Explorer 7
- Sleipnir 2.7.0
- Seahorse 1.1.2
- UserAction Extension 1.0.1
インストール
- ソースをコピーし、テキストエディタに貼り付け
- 貼り付けたソース内の全角文字「onunload」「onkeydown」を半角文字に置換する(wikiwiki.jpのセキュリティ対策のせいで、半角だと貼り付けられませんでした)
- sleipnir のインストールディレクトリ\plugins\seahorse\jkscroll.user.js に保存
ソース
// ==UserScript==
// @name j k Scroll
// @description Press j or k key , and scroll (in case that LDRize are not working on its page)
// @include http*
// @exclude http://fastladder.com/reader/*
// @exclude http://www.bloglines.com/*
// @exclude http://mail.google.*/*
// @exclude https://mail.google.*/*
// @exclude http://www.google.*/reader/*
// @exclude https://www.google.*/reader/*
// @exclude http://b.hatena.ne.jp/*
// @exclude http://reader.livedoor.com/reader/*
// @exclude http://*rememberthemilk.com/*
// @version 0.0.2
// ==/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 *
// author Constellation
// version 0.0.1
setTimeout(function() {try{
var SCROLLHEIGHT = 200;
var documentBody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body;
var SmoothScroll = {
steps : 20,
duration : 100,
destinationx: null,
destinationy: null,
timerID: null,
callBackFunc: null,
setCallback : function(f) {
this.callBackFunc = f;
},
stop : function() {
if (this.timerID != null) {
clearTimeout(this.timerID);
this.timerID = null;
}
if ((this.destinationx != null) && (this.destinationy != null)) {
scrollTo(this.destinationx, this.destinationy);
this.destinationx = null;
this.destinationy = null;
}
},
scrollTo : function(destX, destY){
this.destinationx = destX;
this.destinationy = destY;
this.step = 0;
var self = this;
this.prevY = -1;
self.timerID = setTimeout(function() {
var y = documentBody.scrollTop;
yy = self.destinationy - ((self.destinationy - y) / 2);
if ((y == self.prevY) || (Math.abs(self.destinationy - yy) < 1) || (self.step + 1 == self.steps)) {
scrollTo(self.destinationx, self.destinationy);
setTimeout(function() { if (self.callBackFunc != null) self.callBackFunc(); }, 10);
self.destinationx = null;
self.destinationy = null;
} else {
scrollTo(self.destinationx, yy);
self.timerID = setTimeout(arguments.callee, (self.duration / self.steps) * (self.step + 1));
}
self.step++;
this.prevY = y;
}, (this.duration / this.steps) * this.step + 1);
}
};
var ShortcutKey = {
repKey: {
'8': 'BS','9': 'TAB','13': 'Enter','27': 'ESC',
'33': 'PageUp','34': 'PageDown',
'35': 'End','36': 'Home',
'37': 'Left','38': 'Up','39': 'Right','40': 'Down',
'45': 'Insert','46': 'Delete',
'188': ',', '189': '-', '190': '.','191': '/', '192': '@',
'219': '[', '220': '\\', '221': ']', '222': '^', '226': '\\'
},
deepKey: ['ESC', 'TAB', 'Home', 'End', 'Insert', 'Delete', 'C-.+', 'A-.+'].join('|'),
keyEvent: [],
init: function() {
document.body.attachEvent('onkeydown', ShortcutKey.keyHandle);
window.attachEvent('onunload', function() {
document.body.detachEvent('onkeydown', ShortcutKey.keyHandle);
window.detachEvent('onunload', arguments.callee);
});
},
keyHandle: function(event) {
var event = window.event;
var key = '';
var rep = false;
for (var i in ShortcutKey.repKey) {
if (i == event.keyCode) {
key = ShortcutKey.repKey[i];
rep = true;
break;
}
}
if (key == '')
key = String.fromCharCode(event.keyCode).toLowerCase();
key = (event.shiftKey) ? "S-" + key : key;
key = (event.ctrlKey) ? "C-" + key : key;
key = (event.altKey || event.metaKey) ? "A-" + key : key;
var re = new RegExp(ShortcutKey.deepKey);
var isDeep = re.test(key);
if ((document.activeElement.tagName.match(/input|textarea/i)) && (!isDeep)) return;
var func = ShortcutKey.keyEvent[key];
if(func){
func();
event.cancelBubble = true;
event.returnValue = false;
}
},
add: function(key, func) {
ShortcutKey.keyEvent[key] = func;
}
}
ShortcutKey.init();
if ((window.LDRize) && (window.LDRize.getCurrentParagraph())) {
window.LDRize.addKeyBind('S-j', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop + SCROLLHEIGHT);
});
window.LDRize.addKeyBind('S-k', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop - SCROLLHEIGHT);
});
} else {
ShortcutKey.add('j', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop + SCROLLHEIGHT);
});
ShortcutKey.add('k', function() {
SmoothScroll.stop();
SmoothScroll.scrollTo(0, documentBody.scrollTop - SCROLLHEIGHT);
});
}
}catch(e){}
}, 0);