美文网首页
自动滚动屏幕

自动滚动屏幕

作者: 破旧的大卡车 | 来源:发表于2018-10-29 22:42 被阅读15次

    最近迷上了圣殿春秋, 恰好网上有电子版. 稍微调了下格式, 然后写了个油猴脚本, 实现自动翻半屏.

    圣殿春秋在线地址: http://www.99lib.net/book/9182/

    stylish

    稍微改下样式:

    #content>div {
        font-size:22px;
        font-family:"Microsoft YH";
        max-width:760px;
        text-align:justfied;
        margin:0 auto;
    }
    

    TamperMonkey

    // ==UserScript==
    // @name         AutoScroll
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  try to take over the world!
    // @author       You
    // @match        http://www.99lib.net/*
    // @grant        none
    // ==/UserScript==
    
    (function() {
        'use strict';
        var speed=50; var inispeed=speed;
        var initialIntv=50; //50s
        var ExeTimer; var currentSpeed;
        function ScrollHalfDown(){
            var currentPos=document.documentElement.scrollTop || document.body.scrollTop;
            var halfwh=window.innerHeight/2;
            document.documentElement.scrollTop = document.body.scrollTop =currentPos+halfwh;
            //window.scrollTo(0, document.body.clientHeight +window.innerHeight/2);
        }
        function SetSpeed(e){
            var evt = e || window.event;
            var keycode=evt.keyCode;
            console.log(keycode);
            if ( evt.ctrlKey){
                if (keycode == '38'){
                    speed=speed-5;
                } else if (keycode=='40'){
                    speed=speed+5;
                }
                if (speed<=0){
                    speed=0;
                }
                console.log(keycode,speed);
                clearInterval(ExeTimer);
                currentSpeed=initialIntv*(speed/inispeed) * 1000;
                ExeTimer=setInterval(ScrollHalfDown, currentSpeed);
                console.log(currentSpeed);
                if (evt.altKey){
                    if (keycode=='80'){
                        clearInterval(ExeTimer);
                    }else if(keycode=='83'){
                        ExeTimer=setInterval(ScrollHalfDown, currentSpeed);
                    }
                }
            }
        }
    
        ExeTimer=setInterval(ScrollHalfDown, initialIntv*1000);
        document.onkeyup=SetSpeed;
    })();
    

    主要功能: ctrl+上箭头加速, ctrl+下箭头减速. 默认速度50s翻一页.

    目前好像ctrl+alt+p暂停滚动不行;

    相关文章

      网友评论

          本文标题:自动滚动屏幕

          本文链接:https://www.haomeiwen.com/subject/lwaitqtx.html