Optimize Browser

Have a better experience to use browser.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Optimize Browser
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  Have a better experience to use browser.
// @author       Eugene Liu
// @match        *://*/*
// ==/UserScript==

(function () {//Ignore MouseWheel,only care key and mouse.
    var timerID;
    var timeout;
    var speed = 50;
    var EugeneScroll;
    var stopAutoScroll = false;

    document.onkeydown = function (event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 118) {
            if (stopAutoScroll === false) {
                stopAutoScroll = true;
            } else {
                stopAutoScroll = false;
            }
        }
    };

    function ScreenSaver(settings) {
        timeout = settings.timeout;
        document.body.onmousemove = document.body.onmousedown = document.body.onkeydown = document.body.onkeypress = ScreenSaver.prototype.onevent;
        timerID = window.setTimeout(function () {
            if (!stopAutoScroll) {
                moveDown();
            }
        }, timeout);
    }

    ScreenSaver.prototype.onevent = function (e) {
        window.clearTimeout(timerID);
        stopMove();
        timerID = window.setTimeout(function () {
            if (!stopAutoScroll) {
                moveDown();
            }
        }, timeout);
    };

    function initScreenSaver() {
        new ScreenSaver({timeout: 5000});
    }

    function moveDown() {
        EugeneScroll = setInterval(function () {
            window.scrollBy(0, +1);
        }, speed);
    }

    function stopMove() {
        clearInterval(EugeneScroll);
    }

    window.onload = function () {
        initScreenSaver();
    }
})();