var timeToJoin = '18:13';
var today = new Date();
var time = today.getHours() + ":" + today.getMinutes();
var SST = 'https://meet.google.com/rnc-akmx-ubk';
if (time == timeToJoin) {
joinClass();
}
function joinClass() {
location.href = SST;
setTimeout(offMicVideo, 10000);
}
function offMicVideo() {
var video = document.getElementsByClassName('I5fjHe');
var mic = document.getElementsByClassName('oTVIqe');
for (var i = 0; i < video.length; i++) {
video[i].click();
}
for (var i = 0; i < mic.length; i++) {
mic[i].click();
}
}
这是我的javascript代码,它只需要在正确的时间打开谷歌,加入我的在线课程。如果
(time == timeToJoin) {
joinClass();
}
这里发生的事情是,我给出的条件是true
一分钟,因此机器人一直试图加入一个类一分钟,它打开链接,然后再次打开相同的链接,直到条件变为假。
我尽力解决了这个问题,但不知道为什么它们都不起作用。
由于每次脚本都是从头开始的,因此您需要确定视频类是否在上一次运行中加入。你可以使用Chrome的存储API。文件说明:
您必须声明;存储";扩展清单中使用存储API的权限。例如:
{ "name": "My extension", ... "permissions": [ "storage" ], ... }
要为您的扩展存储用户数据,您可以使用
storage.local
:的storage.sync
[…]chrome.storage.sync.set({key: value}, function() { console.log('Value is set to ' + value); }); chrome.storage.sync.get(['key'], function(result) { console.log('Value currently is ' + result.key); });
因此,一旦您调整了清单,请更改代码的以下部分:
if (time == timeToJoin) {
joinClass();
}
到此:
chrome.storage.sync.get({ classStarted: false }, function({classStarted}) {
if ((time === timeToJoin) === classStarted) return; // nothing to do
if (!classStarted) {
// Persist the fact that we start the class, and call joinClass once it is persisted
chrome.storage.sync.set({ classStarted: true }, joinClass);
} else {
// At least one minute elapsed, so we can clean up the persisted value now...
chrome.storage.sync.remove("classStarted");
}
});