// ==UserScript== // @name 防掉线刷新外挂 // @namespace http://tampermonkey.net/ // @version 0.3 // @description 定期ajax刷新你的网页,防止你掉线 // @author lnwazg // @match *://*/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; //防掉线外挂: //如果你登录的系统session过期很快,那么请将这段代码粘贴到chrome浏览器的console中,即可有效防掉线。 //使用步骤: //在chrome浏览器下,按F12,打开console,将以下代码粘贴进去,回车即可。不要关闭当前tab,即可防掉线. (function(){ Date.prototype.format = function (fmt) { // author: meizz var o = { "M+": this.getMonth() + 1, // 月份 "d+": this.getDate(), // 日 "h+": this.getHours(), // 小时 "m+": this.getMinutes(), // 分 "s+": this.getSeconds(), // 秒 "q+": Math.floor((this.getMonth() + 3) / 3), // 季度 "S": this.getMilliseconds() // 毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "") .substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }; 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() { return (new Date()).format("yyyy-MM-dd hh:mm:ss"); } var interval = 1000 * 120; //刷新间隔 var req = function(){get(url);} setInterval(req, interval); })(); })();