代碼:
// ==UserScript==
// @name 自動評論嗶哩嗶哩視頻
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.bilibili.com/*
// @grant none
// ==/UserScript==
(function(){
// 等待兩秒鐘再進行評論
setTimeout(function(){
var c=["陌生人好好的呦。","別看啦,照顧好自己","喧鬧的世界,看到這條評論。洗洗睡吧吧!"];
var n = -1;
var m = 3;
var temp_count = Math.floor(Math.random()*(n-m+1))+m;//取m-n之間的隨機數 [m,n]
//document.getElementsByClassName("tool-item-comment")[0].click();//能夠打開評論區啦
var time = new Date();
var t = " 我在: " +time.getFullYear()+"年 "+(time.getMonth()+1)+"月 "+time.getDate()+"日 "+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds()+" 來過!";
//document.getElementById("comment_content").value = t//評論時間
document.getElementsByClassName("ipt-txt")[0].value = c[temp_count] + t;//能夠賦值啦
document.getElementsByClassName("comment-submit")[0].click(); //發表評論成功!
},9999);//ajax do something
})();
結果: