Javascript 随机导航到 URL
Javascript to navigate to random URL
我正在尝试为论坛编写用户脚本,我要求它随机导航到不同的 URLs。
基本思路是,我想大部分时间都在线以增加我的在线时间。一段时间不活动后,论坛不会增加在线花费时间(假设 5 分钟)。
那么,我如何编写 javascript 代码来继续导航到论坛中的不同 URL。
这是论坛帖子的格式:
somesite.xxx/showthread.php?tid=xxxxxxx
所以脚本应该访问一些随机线程(比如 0123456),等待 5 分钟并访问下一个随机线程(比如 1123456)并保持这个循环重复。
我试过了:
setTimeout(function() {
location.href = "somesite.xxx/showthread.php?tid=4128749";
}, 10000);
setTimeout(function() {
location.href = "somesite.xxx/showthread.php?tid=5128749";
}, 10000);
setTimeout(function() {
location.href = "somesite.xxx/showthread.php?tid=3128749";
}, 10000);
但是我无法继续添加所有无数的 URL,而且上面的代码也不起作用,继续附加站点 URL,例如 somesite.xxx/somesite.xxx/。 ..
那么,您需要以某种方式生成 URL 列表。无论是来自 API、PHP 还是 JavaScript 数组、文本文件,等等。否则你必须生成一个随机的 7 位数字并希望能成功。
一旦你得到你的线程列表,将它们变成一个数组,然后随机选择一个,然后 运行 你的 setTimeout 函数(在 [=13= 之前缺少 window.
])
var threads = ['4128749', '5128749', '3128749', ...];
var random = threads[Math.floor(Math.random() * threads.length)];
setTimeout(function(){
window.location.href = 'http://somesite.xxx/showthread.php?tid=' + random;
}, 10000);
如果您不关心未命中,或者您知道所有 7 位数字都会产生一个线程,您可以随机生成数字,然后将位置设置为该数字。
//Generate random 7 digit number
var random = Math.floor(Math.random()*9000000) + 1000000;
setTimeout(function(){
window.location.href = 'http://somesite.xxx/showthread.php?tid=' + random;
}, 10000);
比如说,你有一个 href 数组。例如hrefArray = [href1, href2, ...]。现在您可以通过 href 进行循环。
const hrefArray = ['somesite.xxx/showthread.php?tid=4128749', 'somesite.xxx/showthread.php?tid=5128749'];
const len = hrefArray.length;
for (let i = 0; i < len; i++) {
setTimeout(function() {
location.href = hrefArray[i];
}, (Math.floor(Math.random() * i) + 1000);
}
在执行函数时使用 setInterval
而不是 setTimeout
反复作为参数传递。
const timeout = 300000;
setInterval(function () {
const sevenRandom = Math.floor(100000 + Math.random() * 9000000);
const windowHandle = window.open('somesite.xxx/showthread.php?tid=' + sevenRandom, '_blank');
setTimeout(function () {
windowHandle.close();
}, timeout);
}, timeout);
将上面的代码片段粘贴到浏览器的控制台中,它会每隔五分钟在新标签页中打开您的URL。它还会关闭之前打开的选项卡,以避免打开大量选项卡。
注意:避免将此用于任何类型的垃圾邮件,并且仅用于真正的目的。
我正在尝试为论坛编写用户脚本,我要求它随机导航到不同的 URLs。
基本思路是,我想大部分时间都在线以增加我的在线时间。一段时间不活动后,论坛不会增加在线花费时间(假设 5 分钟)。
那么,我如何编写 javascript 代码来继续导航到论坛中的不同 URL。
这是论坛帖子的格式: somesite.xxx/showthread.php?tid=xxxxxxx 所以脚本应该访问一些随机线程(比如 0123456),等待 5 分钟并访问下一个随机线程(比如 1123456)并保持这个循环重复。
我试过了:
setTimeout(function() {
location.href = "somesite.xxx/showthread.php?tid=4128749";
}, 10000);
setTimeout(function() {
location.href = "somesite.xxx/showthread.php?tid=5128749";
}, 10000);
setTimeout(function() {
location.href = "somesite.xxx/showthread.php?tid=3128749";
}, 10000);
但是我无法继续添加所有无数的 URL,而且上面的代码也不起作用,继续附加站点 URL,例如 somesite.xxx/somesite.xxx/。 ..
那么,您需要以某种方式生成 URL 列表。无论是来自 API、PHP 还是 JavaScript 数组、文本文件,等等。否则你必须生成一个随机的 7 位数字并希望能成功。
一旦你得到你的线程列表,将它们变成一个数组,然后随机选择一个,然后 运行 你的 setTimeout 函数(在 [=13= 之前缺少 window.
])
var threads = ['4128749', '5128749', '3128749', ...];
var random = threads[Math.floor(Math.random() * threads.length)];
setTimeout(function(){
window.location.href = 'http://somesite.xxx/showthread.php?tid=' + random;
}, 10000);
如果您不关心未命中,或者您知道所有 7 位数字都会产生一个线程,您可以随机生成数字,然后将位置设置为该数字。
//Generate random 7 digit number
var random = Math.floor(Math.random()*9000000) + 1000000;
setTimeout(function(){
window.location.href = 'http://somesite.xxx/showthread.php?tid=' + random;
}, 10000);
比如说,你有一个 href 数组。例如hrefArray = [href1, href2, ...]。现在您可以通过 href 进行循环。
const hrefArray = ['somesite.xxx/showthread.php?tid=4128749', 'somesite.xxx/showthread.php?tid=5128749'];
const len = hrefArray.length;
for (let i = 0; i < len; i++) {
setTimeout(function() {
location.href = hrefArray[i];
}, (Math.floor(Math.random() * i) + 1000);
}
在执行函数时使用 setInterval
而不是 setTimeout
反复作为参数传递。
const timeout = 300000;
setInterval(function () {
const sevenRandom = Math.floor(100000 + Math.random() * 9000000);
const windowHandle = window.open('somesite.xxx/showthread.php?tid=' + sevenRandom, '_blank');
setTimeout(function () {
windowHandle.close();
}, timeout);
}, timeout);
将上面的代码片段粘贴到浏览器的控制台中,它会每隔五分钟在新标签页中打开您的URL。它还会关闭之前打开的选项卡,以避免打开大量选项卡。
注意:避免将此用于任何类型的垃圾邮件,并且仅用于真正的目的。