forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatchForBug533054.uc.js
80 lines (71 loc) · 2.52 KB
/
patchForBug533054.uc.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
// ==UserScript==
// @name patchForBug533054.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Bug 533054 - Shift+Page Up and Shift+Page Down don't select in the view source window Bug 309009 - Shift+pageUp does not select a page of text prior to the cursor and shift+page down does not select page of text after the cursor
// @include main
// @include chrome://global/content/viewSource.xul
// @include chrome://global/content/viewPartialSource.xul
// @compatibility Firefox 3.0 3.5 3.6 3.7
// @author Alice0775
// @version 2009/12/05
// ==/UserScript==
var bug533054 = {
NUMLINE: 10,
init: function(){
window.addEventListener('unload', this, false);
window.addEventListener('keydown', this, false);
},
uninit: function(){
window.removeEventListener('unload', this, false);
window.removeEventListener('keydown', this, false);
},
handleEvent: function(event){
switch (event.type) {
case 'unload':
this.uninit();
break;
case 'keydown':
if (!event.shiftKey || event.ctrlKey || event.altKey || event.metaKey)
return;
if (this.isParentEditableNode(event.originalTarget))
return;
//this.debug(event.keyCode);
if (event.keyCode == KeyEvent.DOM_VK_PAGE_UP)
this.key(event, KeyEvent.DOM_VK_UP);
else if (event.keyCode == KeyEvent.DOM_VK_PAGE_DOWN)
this.key(event, KeyEvent.DOM_VK_DOWN);
break;
}
},
key: function(event, code) {
window.removeEventListener('keydown', this, false);
for (var i = 0;i < this.NUMLINE; i++) {
var e = document.createEvent("KeyboardEvent");
e.initKeyEvent ("keypress", true, true, null,
event.ctrlKey, event.altKey, event.shiftKey, event.metaKey,
code, 0)
event.originalTarget.dispatchEvent(e);
}
window.addEventListener('keydown', this, false);
},
isParentEditableNode: function(node){
//if (Components.lookupMethod(node.ownerDocument, 'designMode').call(node.ownerDocument) == 'on')
// return node;
while (node && node.parentNode) {
try {
node.QueryInterface(Ci.nsIDOMNSEditableElement);
return node;
}
catch(e) {
}
node = node.parentNode;
}
return null;
},
debug: function(aMsg){
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg);
}
}
bug533054.init();