吾爱破解论坛增强 - 自动签到、翻页

吾爱破解论坛自动签到、自动翻页

目前為 2020-10-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         吾爱破解论坛增强 - 自动签到、翻页
// @version      1.0.1
// @author       X.I.U
// @description  吾爱破解论坛自动签到、自动翻页
// @match        *://www.52pojie.cn/*
// @icon         https://www.52pojie.cn/favicon.ico
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @license      GPL-3.0 License
// @run-at       document-end
// @namespace    https://greasyfork.org/scripts/412680
// ==/UserScript==

(function() {
    qianDaoBack();
    qianDao();
    pageLoading();

    // 自动签到
    function qianDao() {
        var qiandao = document.querySelector('#um p:last-child a:first-child');
        if (qiandao != null){
            if(qiandao.href === "https://www.52pojie.cn/home.php?mod=task&do=apply&id=2")
            {
                qiandao.click();
            }
        }
    }

    // 签到后返回
    function qianDaoBack() {
        var qiandaoback = document.querySelector('#messagetext.alert_btnleft');
        if (qiandaoback != null){
            qiandaoback.click();
        }
    }

    // 自动翻页
    function pageLoading() {
        var patt = /forum-\d+-\d+\.html/
        if (patt.test(location.pathname)){
            windowScroll(function (direction, e) {
                if (direction === "down") { // 下滑才准备翻页
                    var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
                    let scrollDelta = 666;
                    if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
                        if (document.querySelector('#autopbn').innerText == "下一页 »"){ // 如果已经在加载中了,就忽略
                            document.querySelector('#autopbn').click();
                        }
                    }
                }
            });
        }
    }

    // 滚动条事件
    function windowScroll(fn) {
          var beforeScrollTop = document.documentElement.scrollTop,
              fn = fn || function () {};
          setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
            window.addEventListener("scroll", function (e) {
              var afterScrollTop = document.documentElement.scrollTop,
                  delta = afterScrollTop - beforeScrollTop;
              if (delta == 0) return false;
              fn(delta > 0 ? "down" : "up", e);
              beforeScrollTop = afterScrollTop;
            }, false);
          }, 1000)
        }
})();