forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatchForBug675866_choppyScrollRemover.uc.js
252 lines (227 loc) · 7.61 KB
/
patchForBug675866_choppyScrollRemover.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// ==UserScript==
// @name patchForBug675866_choppyScrollRemover.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Workaround Bug 675866 scrolling complex pages like Engadget is consistently slower and jerkier than the competition and Bug 705174 Bug 705361 ftp slow scroll and hover
// @include main
// @compatibility Firefox 7-
// @author Alice0775
// @version 2011/11/08 13:00 タブ選択時
// @version 2011/10/24 19:00 xxx scroll amount become small when forst tick of wheel scroll
// @version 2011/10/22 12:00
// @Note コンテンツにDIV要素を挿入しているので留意
// ==/UserScript==
var patchForBug675866_choppyScrollRemover = {
DELAY: 400,
timer: null,
scrolling: false,
KscreenId : "__patchForBug675866_Screen",
get box() {
delete this.box;
return this.box = document.getElementById("appcontent");
},
get autoscroller() {
delete this.autoscroller;
return this.autoscroller = document.getElementById("autoscroller");
},
init : function() {
gBrowser.tabContainer.addEventListener('TabSelect', this, false);
gBrowser.tabContainer.addEventListener('mousedown', this, true);
window.addEventListener('resize', this, false);
this.DELAY_SHOW = Services.prefs.getIntPref("browser.overlink-delay");
this.box.addEventListener('scroll', this, true);
this.autoscroller.addEventListener('popupshowing', this, false);
window.addEventListener('unload', this, false);
var style = String(<![CDATA[
@namespace url(http://www.w3.org/1999/xhtml);
#__patchForBug675866_Screen {
left : 0 !important;
top : 0 !important;
width : 100%;
height : 100%;
border : 0 !important;
margin : 0 !important;
padding : 0 !important;
background : transparent !important;
position : absolute !important;
display : none !important;
z-index : 1000000 !important;
}
#__patchForBug675866_Screen[on] {
display : -moz-box !important;
}
@-moz-document url-prefix(ftp://) {
tbody > tr:nth-child(2n+1) {
background:#efefff;
/*color:#000000;*/
}
tbody > tr:nth-child(2n) {
background-color: #feffff;
/*color:#000000;*/
}
tbody > tr:hover {
outline: none !important;
background-color: #ccccff;
}
}
]]>).replace(/\s+/g, " ");
code = "data:text/css;charset=utf-8," + encodeURIComponent(style);
var uri = Services.io.newURI(code, null, null);
Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService)
.loadAndRegisterSheet(uri, Ci.nsIStyleSheetService.USER_SHEET);
},
uninit : function() {
gBrowser.tabContainer.removeEventListener('TabSelect', this, false);
gBrowser.tabContainer.removeEventListener('mousedown', this, true);
window.removeEventListener('resize', this, false);
window.removeEventListener('unload', this, false);
this.box.removeEventListener('scroll', this, true);
this.autoscroller.removeEventListener('popupshowing', this, false);
if (this.timer)
clearTimeout(this.timer);
},
insertScreen : function(win) {
if (typeof win == 'undefined')
win = content;
if (/^ftp:/.test(win.location.href))
return;
if (win.frames && win.frames.length) {
var self = this;
Array.prototype.slice.call(win.frames).forEach(function(aSubFrame) {
self.insertScreen(aSubFrame);
});
}
var doc = win.document;
// skip when document is in design mode
if (Components.lookupMethod(doc, 'designMode').call(doc) == 'on')
return;
var screen = doc.getElementById(this.KscreenId);
// skip already created SCREEN
if (screen) {
return;
}
// skip no body element
var bodies = doc.getElementsByTagName("body");
if(bodies.length == 0)
return;
// skip when bosy is in ContentEditable
if (bodies[0].isContentEditable)
return;
var screen = doc.createElement("div");
screen.setAttribute("id", this.KscreenId);
var screen = bodies[0].insertBefore(screen, bodies[0].lastChild);
},
screenSwitch: function(on, win) {
if (typeof win == 'undefined')
win = content;
if (/^ftp:/.test(win.location.href))
return;
if (win.frames && win.frames.length) {
var self = this;
Array.prototype.slice.call(win.frames).forEach(function(aSubFrame) {
self.screenSwitch(on, aSubFrame);
});
}
var doc = win.document;
var screen = doc.getElementById(this.KscreenId);
// skip if no SCREEN element
if (!screen)
return;
if (on) {
var bodies = doc.getElementsByTagName("body");
screen.setAttribute('on', true);
// xxx hack for document mode
var rectObject = screen.getBoundingClientRect();
var height = Math.floor(rectObject.bottom - rectObject.top);
var scrollH = Math.max(bodies[0].parentNode.scrollHeight, bodies[0].offsetHeight);
var scrollW = Math.max(bodies[0].parentNode.scrollWidth , bodies[0].offsetWidth);
//userChrome_js.debug(height+ " " +scrollH);
if (height < scrollH) {
// xxx -5 ; This prevent that scroll amount become small when forst tick of wheel scroll
screen.style.setProperty('min-height', scrollH-5 + 'px', 'important');
screen.style.setProperty('min-width', scrollW-5 + 'px', 'important');
}
} else {
screen.removeAttribute('on');
screen.style.removeProperty('min-height');
screen.style.removeProperty('min-width');
}
},
scroll: function(event) {
if (this.autoscroller.state == "open" ||
this.autoscroller.state == "showing")
return;
if ("GrabScroll" in window && GrabScroll.mStatus == 2)
return;
var doc = event.originalTarget;
if (doc instanceof HTMLDocument &&
doc.defaultView.top == content) {
doc = doc.defaultView.top.document;
if (!this.scrolling) {
this.addListener();
}
}
if (this.timer)
clearTimeout(this.timer);
this.timer = setTimeout(function(self) {
self.removeListener();
}, this.DELAY, this);
},
addListener: function() {
//userChrome_js.debug('addListener');
this.scrolling = true;
this.insertScreen();
this.screenSwitch(true);
},
removeListener: function() {
//userChrome_js.debug('removeListener');
if (this.timer)
clearTimeout(this.timer);
this.scrolling = false;
this.screenSwitch(false);
},
popupshowing: function(event) {
this.autoscroller.addEventListener('popuphidden', this, false);
this.addListener();
},
popuphidden: function(event) {
this.autoscroller.removeEventListener('popuphidden', this, false);
this.removeListener();
},
resized: null,
resize: function(event) {
this.box.removeEventListener('scroll', this, true);
if (this.resized)
clearTimeout(this.resized);
this.resized = setTimeout(function(self) {
self.removeListener();
self.box.addEventListener('scroll', self, true);
}, 500, this);
},
handleEvent: function(event) {
switch (event.type) {
case 'scroll':
this.scroll(event);
break;
case 'mousedown':
if (event.originalTarget.id != this.KscreenId)
return;
//no break
case 'TabSelect':
this.removeListener();
break;
case 'popupshowing':
this.popupshowing();
break;
case 'popuphidden':
this.popuphidden();
break;
case 'resize':
this.resize(event);
break;
case 'unload':
this.uninit();
break;
}
}
}
patchForBug675866_choppyScrollRemover.init();