Greasy Fork is available in English.

豆瓣电影自动加载下一页 TENG

浏览豆瓣电影、电视剧分类时自动 加载下一页

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         豆瓣电影自动加载下一页 TENG
// @namespace    none
// @version      1.3
// @description  浏览豆瓣电影、电视剧分类时自动 加载下一页
// @author       teng
// @include        http*://movie.douban.com*
// @include        http*://movie.douban.com/tag*
// @grant        none
// ==/UserScript==

       (function () {
            'use strict';
            window.onload = function () {
                //防抖函数
                function debound(fn, delay){
                    let flag = null
                    return function(){
                        if(flag!==null){
                            clearTimeout(flag)
                        }
                        flag = setTimeout(()=>{
                            fn()
                        },delay)
                    }
                }
                //
                function getScrollTop() {
                    var scrollTop = 0,
                        bodyScrollTop = 0,
                        documentScrollTop = 0;
                    if (document.body) {
                        bodyScrollTop = document.body.scrollTop;
                    }
                    if (document.documentElement) {
                        documentScrollTop = document.documentElement.scrollTop;
                    }
                    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
                    return scrollTop;
                }
                //文档的总高度
                function getScrollHeight() {
                    var scrollHeight = 0,
                        bodyScrollHeight = 0,
                        documentScrollHeight = 0;
                    if (document.body) {
                        bodyScrollHeight = document.body.scrollHeight;
                    }
                    if (document.documentElement) {
                        documentScrollHeight = document.documentElement.scrollHeight;
                    }
                    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight :
                        documentScrollHeight;
                    return scrollHeight;
                }
                //浏览器视口的高度
                function getWindowHeight() {
                    var windowHeight = 0;
                    if (document.compatMode == "CSS1Compat") {
                        windowHeight = document.documentElement.clientHeight;
                    } else {
                        windowHeight = document.body.clientHeight;
                    }
                    return windowHeight;
                }


                function clickLoadMore() {
                    var loadMore = document.querySelector(".more");
                    if (loadMore) {
                        loadMore.click();
                    }
                }


                window.onscroll = function () {
                    if (getScrollTop() + getWindowHeight() == getScrollHeight()) {
                        debound(clickLoadMore, 500)()
                    }
                };

            }
        })();