TopScroll

Быстрая прокрутка страницы вверх/вниз.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name	TopScroll
// @description	Быстрая прокрутка страницы вверх/вниз.
// @namespace	https://forum.mozilla-russia.org/viewtopic.php?pid=719386#p719386
// @include 	*
// @version	1.0
// ==/UserScript==

topScroll = {

    injectDiv: function() {
        var body = document.getElementsByTagName("body")[0];
        var div = document.createElement("div");
        div.id = "topscroll-chrome-extension-bar";
        div.setAttribute("style", "position: fixed !important; top: 0 !important; left: 0 !important; bottom: 0 !important; margin: 0 !important; padding: 0 !important; width: 5px !important; height: 100% !important; border-style: none !important; box-shadow: none !important; opacity: 0 !important; z-index: 2147483647 !important;");
        div.onclick = topScroll.scrollUp;
        div.oncontextmenu = topScroll.scrollDown;
        body.appendChild(div);
    },

    scrollUp: function() {
        if (window.pageYOffset === 0) {
            topScroll.scrollTo(topScroll.lastScrollPosition);
            topScroll.lastScrollPosition = 0;
        } else {
            topScroll.lastScrollPosition = window.pageYOffset;
            topScroll.scrollTo(0);
        }
    },

    scrollDown: function() {
        var bottomOffset = document.documentElement.scrollHeight - window.innerHeight;
        if (window.pageYOffset === bottomOffset) {
            topScroll.scrollTo(topScroll.lastScrollPosition);
            topScroll.lastScrollPosition = bottomOffset;
        } else {
            topScroll.lastScrollPosition = window.pageYOffset;
            topScroll.scrollTo(bottomOffset);
        }
        return false; // Prevent context menu appearing
    },

    scrollTo: function(endY) {
        var duration = 150;
        var startY = window.scrollY;
        var distance = Math.max(endY,0) - startY;
        var startTime = new Date().getTime();
        (function loopScroll() {
            setTimeout(function () {
                var p = Math.min((new Date().getTime() - startTime) / duration, 1); // Progress 0→1
                var y = Math.max(Math.floor(startY + distance*(p < 0.5 ? 2*p*p : p*(4 - p*2)-1)), 0);
                window.scrollTo(window.pageXOffset, y);
                if (p < 1) {
                    loopScroll();
                }
            }, 1)
        })();
    }
};

topScroll.injectDiv();