// ==UserScript==
// @name 巴蜀OJ自动发信机+自动删信机
// @name:en Auto mail sender + deleter for BSOJ
// @namespace https://greasyfork.org/users/1265383
// @version 3.2
// @description 自动向指定用户发送n条消息,1秒1000条。自动删除当前页码上的所有信息,瞬间删完。自动删除所有信息,几秒删完。
// @description:en Automatically send n messages to the specified user, 1000 message every second.Automatically deletes all information on the current page number in an instant.Automatically deletes all information quickly.
// @author 123asdf123(luogu 576074)
// @match https://oj.bashu.com.cn/code/mail.*
// @icon https://oj.bashu.com.cn/favicon.ico
// @license GPL3.0+SATA
// @grant none
// @downloadURL none
// ==/UserScript==
var autosendb=document.createElement("span"),delb=document.createElement("span"),clearb=document.createElement("span"),automail=document.createElement("div");
function insertAfter(newElement, targetElement) {
let parent = targetElement.parentNode;
if (parent.lastChild == targetElement) {
parent.appendChild(newElement);
} else {
parent.insertBefore(newElement, targetElement.nextSibling);
}
}
function send(user,title,content){
document.getElementById("sendnew").click();
document.getElementById("to_input").value=user;
document.getElementById("title_input").value=title;
document.getElementById("detail_input").value=content;
let d=$('#send_form').serialize();
while(document.body.children.length){
document.body.children[0].remove();
}
window.document.body.appendChild(document.createElement("div"))
while(localStorage["auto-send-remain"]!=0){
localStorage["auto-send-remain"]--;
$.ajax({
type:"POST",
url:"ajax_mailfunc.php?op=send",
data:d,
});
// setTimeout("",1000);
}
}
function sendmessage(){
localStorage["auto-send-remain"]=parseInt(prompt("Times?","1"));
localStorage["auto-send-user"]=document.getElementById("to_input").value;
localStorage["auto-send-title"]=document.getElementById("title_input").value;
localStorage["auto-send-content"]=document.getElementById("detail_input").value;
// location.reload();
}
function offmessage(){
automail.className="modal hide";
automail.setAttribute("aria-hidden","true");
automail.setAttribute("style","display: none;");
document.getElementById("AutoMailModal_block").remove();
}
function delmessage(){
let need=document.querySelectorAll(".btn.btn-mini.btn-danger");
need.forEach(function (message) {
message.click();
});
}
function clearmessage(){
let x=confirm("Are you sure?");
if(x==true){
localStorage["auto-clear"]=1;
location.reload();
}
}
(function() {
'use strict';
autosendb.innerHTML="Auto-Send";
autosendb.className="btn btn-info";
autosendb.onclick=sendmessage;
delb.innerHTML=" Delete all messages on this page";
delb.className="btn btn-small";
delb.setAttribute("style","margin:5px");
delb.onclick=delmessage;
clearb.innerHTML=" Clear all";
clearb.className="btn btn-small";
clearb.setAttribute("style","margin:5px");
clearb.onclick=clearmessage;
document.getElementById("sendnew").parentNode.appendChild(autosendb);
document.getElementById("sendnew").parentNode.appendChild(delb);
document.getElementById("sendnew").parentNode.appendChild(clearb);
insertAfter(autosendb,document.getElementById("MailModal").children[2].children[0]);
document.getElementById("MailModal").parentNode.appendChild(automail);
if(localStorage["auto-send-done"]==1){
localStorage["auto-send-done"]=0;
var done=document.createElement("div");
done.innerHTML="Done.";
done.className="alert alert-success center alert-popup";
document.body.appendChild(done);
}
if(localStorage.getItem("auto-clear")==null){
localStorage["auto-clear"]=0;
}
if(localStorage["auto-clear"]==1){
let need=document.querySelectorAll(".btn.btn-mini.btn-danger");
need.forEach(function (message) {
message.click();
});
if(need.length==0){
localStorage["auto-clear"]=0;
}
location.reload();
}
if(localStorage.getItem("auto-send-remain")==null){
localStorage["auto-send-remain"]=0;
}
if(localStorage["auto-send-remain"]!=0){
send(localStorage["auto-send-user"],localStorage["auto-send-title"],localStorage["auto-send-content"]);
localStorage["auto-send-done"]=1;
location.reload();
}
})();