Top > LDRize > Extension > jkScroll

LDRize/Extension/jkScroll

Last-modified: 2009-02-23 (月) 16:55:27

LDRizeが無効なサイトでもj,kでスクロール by 958 Edit

概要 Edit

  • LDRizeが無効のときには、"j","k"キーで上下に移動できるようにする SeaHorseスクリプト
  • ついでにLDRizeが有効のときには、"S-j","S-k"キーで上下に固定量スクロールする(ver 0.02で追加)

必須拡張 Edit

  • SeaHorse 1.1.1 以上
  • UserAction Extension 1.0.0 以上

動作確認環境 Edit

  • Windows XP SP2
  • Internet Explorer 7
  • Sleipnir 2.7.0
  • Seahorse 1.1.2
  • UserAction Extension 1.0.1

インストール Edit

  • ソースをコピーし、テキストエディタに貼り付け
  • 貼り付けたソース内の全角文字「onunload」「onkeydown」を半角文字に置換する(wikiwiki.jpのセキュリティ対策のせいで、半角だと貼り付けられませんでした)
  • sleipnir のインストールディレクトリ\plugins\seahorse\jkscroll.user.js に保存

ソース Edit

  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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
-
|
|
|
|
|
|
|
-
|
!
-
-
|
|
!
-
|
|
|
!
!
-
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
-
|
|
!
|
|
!
!
!
|
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ==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);