|
|
@@ -18,7 +18,7 @@
|
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
-/* global window, scrollBy, requestAnimationFrame, Element, document, dispatchEvent, UIEvent, setTimeout */
|
|
|
+/* global window, Element, document, dispatchEvent, UIEvent, setTimeout */
|
|
|
|
|
|
(() => {
|
|
|
|
|
|
@@ -36,17 +36,24 @@
|
|
|
const right = left + boundingRect.width;
|
|
|
return { x: boundingRect.x, y: boundingRect.y, top, bottom, left, right, width: boundingRect.width, height: boundingRect.height };
|
|
|
};
|
|
|
- scrollBy(0, 1);
|
|
|
- requestAnimationFrame(() => scrollBy(0, -1));
|
|
|
+ dispatchEvent(new UIEvent("scroll"));
|
|
|
+ const scrollTop = document.documentElement.scrollTop;
|
|
|
scroll(SCROLL_LENGTH, document.documentElement.scrollHeight - window.innerHeight);
|
|
|
|
|
|
function scroll(offsetY, maxOffsetY) {
|
|
|
document.documentElement.__defineGetter__("scrollTop", () => offsetY);
|
|
|
document.documentElement.__defineGetter__("scrollY", () => offsetY);
|
|
|
window.__defineGetter__("pageYOffset", () => offsetY);
|
|
|
- dispatchEvent(new UIEvent("scroll"));
|
|
|
- if (offsetY < maxOffsetY) {
|
|
|
- window._singleFile_timeoutScroll = setTimeout(() => scroll(offsetY + SCROLL_LENGTH, maxOffsetY), SCROLL_DELAY);
|
|
|
+ processScroll();
|
|
|
+
|
|
|
+ function processScroll() {
|
|
|
+ if (offsetY < maxOffsetY) {
|
|
|
+ offsetY += SCROLL_LENGTH;
|
|
|
+ } else {
|
|
|
+ offsetY = scrollTop;
|
|
|
+ }
|
|
|
+ dispatchEvent(new UIEvent("scroll"));
|
|
|
+ window._singleFile_timeoutScroll = setTimeout(processScroll, SCROLL_DELAY);
|
|
|
}
|
|
|
}
|
|
|
|