[JavaScript] 纯文本查看 复制代码 // ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url] 延时跳转页面示例
// @description 自动延时跳转到指定的一系列页面,
// [url=home.php?mod=space&uid=697773]@include[/url] *
// ==/UserScript==
// 指定要跳转的页面 URL 列表 url 跳转URL time 该页面停留时长 单位s 设置分钟为5*min 小时为
var min = 60;
var hour = 60*min;
var urls = [{"url":"https://www.baidu.com/s?wd=11","time":(5*min)},
{"url":"https://www.52pojie.cn/forum.php?mod=guide&view=newthread","time":6*min},
{"url":"https://www.baidu.com/s?wd=3","time":4*hour},
{"url":"https://www.52pojie.cn/forum.php?mod=guide&view=newthread&a=a","time":11}
];
// 定义计时器变量和页面索引
var localUrl = window.location.href;
console.log("当前页面URL:",localUrl);
var isInclu =false;
var index = 0;
var maxIndex = urls.length-1;
for(let i = 0; i < urls.length; i++) {
let t = urls[i];
console.log(t.url == localUrl);
if(t.url == localUrl){
isInclu = true;
index = urls.indexOf(t);
index++;
index = index > maxIndex ? -1:index;
break;
}
}
if(index == -1){
console.log("最后一个url,任务终止");
return;
}
var countdown;
var n = urls.length;
console.log("index: ", index);
// 设置页面跳转的延迟时间,单位为秒
var delay_init = urls[index].time;
var delay = delay_init;
// 开始倒计时
countdown = setInterval(function() {
console.log("index: ", index, "countdown: ", countdown, "delay: ", delay);
//
if(delay == -1){
console.log("运行完成,结束!");
clearInterval(countdown);
}
// 倒计时结束时,跳转到下一个页面
if (delay == 0) {
window.location.href = urls[index].url;
// 重置延迟时间为下一个
//delay = urls[index].time;
}
// 减少延迟时间
delay--;
}, 1000); |