Greasy Fork

Greasy Fork is available in English.

防掉线刷新外挂

try to take over the world!

当前为 2018-12-26 提交的版本,查看 最新版本

// ==UserScript==
// @name         防掉线刷新外挂
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!
// @author       lnwazg
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //防掉线外挂:
    //如果你登录的系统session过期很快,那么请将这段代码粘贴到chrome浏览器的console中,即可有效防掉线。
    //使用步骤:
    //在chrome浏览器下,按F12,打开console,将以下代码粘贴进去,回车即可。不要关闭当前tab,即可防掉线.
    (function(){
        var url = location.href;
        console.log("[LoginOnlinePlugin "+curentTime()+"] "+url+" 防掉线外挂已启用!");

        function get(url){
            console.log("[LoginOnlinePlugin "+curentTime()+"] request url="+url);
            var xmlHttpReq = null;
            if (window.ActiveXObject){
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            }else if (window.XMLHttpRequest){
                xmlHttpReq = new XMLHttpRequest();
            }
            xmlHttpReq.open("GET", url, true);
            xmlHttpReq.onreadystatechange = function(){
                if (xmlHttpReq.readyState == 4)
                {
                    if (xmlHttpReq.status == 200)
                    {
                        var result = xmlHttpReq.responseText;
                        console.log("[LoginOnlinePlugin "+curentTime()+"] 刷新成功!")
                    }
                }
            };
            xmlHttpReq.send(null);
        }

        function curentTime()
        {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
            return currentdate;
        }

        var interval = 1000 * 120; //刷新间隔
        var req = function(){get(url);}
        setInterval(req, interval);
    })();
})();