動機
疫情期間,天天都有網教通的在線直播課。上課之前經常在做別的事(比如作業之類的),奈何老師喜歡提早點名,直播又有延遲,導致老師說要點名的時候,點名框已經消失了。
於是我就有了寫自動簽到腳本的念頭。
思路
基本情況是:在老師點名的時候,頁面上會出現一個彈窗div,上面有寫“主播正在點名”,還有一個按鈕,另外彈窗只會出現 50 秒,上面會有倒秒,若 50 秒內未簽到你就涼了。
既然是網頁端的東西,考慮用油猴 JS 腳本實現。油猴插件時什么我就不用多說了吧,不懂的自行百度。
在老師點名的時候,我把這部分彈窗的 HTML 代碼給復制了下來:
<div tabindex="-1" class="ant-modal-wrap ant-confirm ant-confirm-info frPuEmWQME" role="dialog">
<div role="document" style="width:520px;" class="ant-modal">
<div class="ant-modal-content">
<div class="ant-modal-body">
<div class="ant-confirm-body">
<i class="anticon anticon-info-circle"></i>
<span class="ant-confirm-title">主播正在點名,倒計時</span>
<div class="ant-confirm-content">
<p>
<mark>27</mark>
<span>秒</span>
</p>
</div>
</div>
</div>
<div class="ant-modal-footer">
<button type="button" class="ant-btn ant-btn-ghost ant-btn-lg">
<span>取 消</span>
</button>
<button type="button" class="ant-btn ant-btn-primary ant-btn-lg">
<span>簽 到</span>
</button>
</div>
</div>
<div tabindex="0" style="width:0;height:0;overflow:hidden;">sentinel</div>
</div>
</div>
那么事情就很清晰了。我們只要在這個元素出現的時候,找到這個簽到按鈕,然后 .click() 模擬點擊一次就可以了。
基本思路是,設一個定時器,每幾秒看一下有沒有這個div,如果有的話就按下這個類名為 ant-btn-primary 的 button。
另外需要注意的是:如果出現其他問題(雖然我一次都沒有遇到過),這個彈窗不是點名框怎么辦?
所以需要再進行一次判斷,看這個 <span class="ant-confirm-title">主播正在點名,倒計時</span> 的 innerHTML 是不是“主播正在點名,倒計時”。
程序實現
話不多說,直接上代碼。
// ==UserScript==
// @name 網教通自動簽到
// @namespace https://www.cnblogs.com/henrylin/
// @version 0.1
// @description 網教通自動簽到
// @author 林洪平
// @match *://web-live.sdp.101.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
setInterval(function () {
if (document.querySelector('.ant-confirm-title') && document.querySelector('.ant-confirm-title').innerHTML == '主播正在點名,倒計時') document.querySelector('.ant-confirm.ant-confirm-info .ant-btn-primary').click();
}, 3000);
})();
短短 9 行解決問題,爽啦!
運行效果

免責聲明
僅供學習參考,不作他用,請全程認真聽講!
