參考:https://www.w3school.com.cn/js/js_date_methods.asp
代碼:
// ==UserScript==
// @name 自動評論舊版本CSDN
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://blog.csdn.net/*
// @grant none
// ==/UserScript==
(function() {
// 等待兩秒鐘再進行評論
setTimeout(function(){
var c=["本條消息自動評論。","別看啦,程序自己寫的評論","喧鬧的世界,收下這條來自機器的評論吧!","花不凋零,水不流!","890"];
var n = -1;
var m = 5;
var temp_count = Math.floor(Math.random()*(n-m+1))+m;//取m-n之間的隨機數 [m,n]
document.getElementsByClassName("btn-comments")[1].click();//能夠滑到舊版評論區啦
//document.getElementById("comment_content").value = c[temp_count];//能夠賦值啦
var time = new Date();
document.getElementById("comment_content").value ="我在: " +time.getFullYear()+"年 "+(time.getMonth()+1)+"月 "+time.getDate()+"日 "+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds()+" 看過本篇博客!";//評論時間
document.getElementsByClassName("btn-comment")[0].click();//發表評論成功!
},2000);//ajax do something
})();