這篇文章主要介紹如何使用JS代碼自動(dòng)刪除稿件的普通彈幕功能,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)專注于企業(yè)營(yíng)銷型網(wǎng)站、網(wǎng)站重做改版、鎮(zhèn)賚網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5建站、商城系統(tǒng)網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為鎮(zhèn)賚等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
1.刪除彈幕的流程分析
判斷彈幕A是否為普通彈幕,是則選中。
點(diǎn)擊刪除彈幕的按鈕,彈出二次確認(rèn)框。
點(diǎn)擊確定,成功刪除。
2.刪除彈幕相關(guān)的html代碼,js代碼2.1 選中
可通過判斷class屬性為"item-front"的標(biāo)簽里是否包含“高級(jí)”兩個(gè)字來(lái)決定是否勾選該彈幕:
document.getElementsByClassName("item-font")[i].innerHTML.match("高級(jí)") getElementsByClassName("bili-checkbox")[i+1].click()
這里i+1是由于有其他標(biāo)簽也使用了“bili-checkbox”屬性。
2.2
用click函數(shù)觸發(fā)點(diǎn)擊“刪除彈幕”按鈕的操作:
document.getElementsByClassName("dele-btn")[0].getElementsByClassName("plain")[0].click();
點(diǎn)擊二次確認(rèn)框:
for (i = 0; i < document.getElementsByClassName("item-attr").length; i++) { if(!document.getElementsByClassName("item-font")[i].innerHTML.match("高級(jí)")){ document.getElementsByClassName("bili-checkbox")[i+1].click(); }}document.getElementsByClassName("dele-btn")[0].getElementsByClassName("plain")[0].click();document.getElementsByClassName("bili-btn")[2].click();
但是由于控制臺(tái)執(zhí)行js的代碼速度過快,會(huì)導(dǎo)致在執(zhí)行到第7行代碼的時(shí)候,class屬性為“bili-btn”的第3個(gè)標(biāo)簽還沒加載出來(lái),所以要在執(zhí)行第7個(gè)語(yǔ)句之前讓其停頓一下。
利用setTimeout()方法可實(shí)現(xiàn)延遲執(zhí)行
setTimeout(function () {document.getElementsByClassName("bili-btn")[2].click(); }, 1000);
或
setTimeout("document.getElementsByClassName(\"bili-btn\")[2].click()",1000);
至此,只實(shí)現(xiàn)了單頁(yè)面的批量刪除1次,但是我們知道,假設(shè)彈幕有N頁(yè),就必須讓以上代碼不斷運(yùn)行,直到第x頁(yè)不包含普通彈幕,然后跳轉(zhuǎn)至第x+1頁(yè)繼續(xù)執(zhí)行以上刪除代碼。
3. 實(shí)現(xiàn)不斷刷新頁(yè)面,當(dāng)刪除完當(dāng)前頁(yè)的普通彈幕時(shí),自動(dòng)跳轉(zhuǎn)至下一頁(yè)
結(jié)合另一篇文章即可實(shí)現(xiàn):https://www.cnblogs.com/wujiecong/p/11549738.html
var timeout = prompt("設(shè)置刷新時(shí)間"); var current = location.href; var page = 0; var count = 0; if(timeout > 0) { setTimeout('reload()', 1000 * timeout); } else { location.replace(current); } function reload() { setTimeout('reload()', 1000 * timeout); if(count<10){ const regex = /pn=(\d+)/; page = page +1; current = current.replace(regex,"pn="+page.toString()) } var frame = '<frameset cols=\'*\'>\n<frame src=\'' + current + '\' /></frameset>'; with(document) { // 引用document對(duì)象,調(diào)用write方法寫入框架,打開新窗口 write(frame); setTimeout(function(){ count = 0 getFrames = window.frames["0"] for (i = 0; i < getFrames.document.getElementsByClassName("item-attr").length; i++) { if(!getFrames.document.getElementsByClassName("item-font")[i].innerHTML.match("高級(jí)")){ getFrames.document.getElementsByClassName("bili-checkbox")[i+1].click(); count = count +1; } } if(count>0){ getFrames.document.getElementsByClassName("dele-btn")[0].getElementsByClassName("plain")[0].click(); setTimeout(function () { getFrames.document.getElementsByClassName("bili-btn")[2].click(); }, 1000); }},2000); // 關(guān)閉上面的窗口 void(close()); }; }
以上是“如何使用JS代碼自動(dòng)刪除稿件的普通彈幕功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)頁(yè)題目:如何使用JS代碼自動(dòng)刪除稿件的普通彈幕功能
新聞來(lái)源:http://chinadenli.net/article28/gjedcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、微信公眾號(hào)、商城網(wǎng)站、搜索引擎優(yōu)化、品牌網(wǎng)站設(shè)計(jì)、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)