1.定时刷新
var timeout = prompt("Set timeout (Second):");
var count = 0;
var current = location.href;
if (timeout > 0) {
setTimeout('reload()', 1000 * timeout);
} else {
location.replace(current);
}
function reload() {
count++;
console.log('每(' + timeout + ')秒自动刷新,刷新次数:' + count);
var fr4me = '<frameset cols=\'*\'>\n<frame src=\'' + current + '\'/>';
fr4me += '</frameset>';
with (document) {
write(fr4me);
void(close())
}
setTimeout('reload()', 1000 * timeout);
}
【JS】console定时刷新页面,不会因刷新而失效 - xiaostudy - 博客园 (cnblogs.com)
2.定时操作某个动作
function ClickConnect() {
console.log("Working..."); // debug 用
// 去選擇按鈕
var connectbutton = document.querySelector(
"colab-toolbar-button" +
"#connect-icon.big-icon.icon-okay");
// 點個兩下
connectbutton.click(); connectbutton.click();
};
// 設定固定每 10 分鐘點一下
const stopit = setInterval(
ClickConnect, 10 * 60 * 1000);
// 這行沒有沒關係,只是避免停不下來
const stopping = stopper => clearInterval(stopper);