// ==UserScript== // @name 巴哈姆特之刪除動畫瘋中獎信件 // @description 一鍵刪除惱人的中獎信件 // @namespace nathan60107 // @version 1.0 // @author nathan60107(貝果) // @homepage https://home.gamer.com.tw/homeindex.php?owner=nathan60107 // @match https://mailbox.gamer.com.tw/?l=1 // @grant none // @downloadURL none // ==/UserScript== var myMailBox = Array(), myDate = Array();//暫存信件編號與日期的變數 function isAniBabi(mail){//檢查是否是巴幣中獎信 return null!=mail.match(/恭喜您於[\d\/]+答對了動畫瘋的問答遊戲!\n本次獎勵:[\d]+ 巴幣\n目前已完成巴幣的發送!\n\n--\n本信件為系統通知信件,請勿回覆!/); } function strip(html){//去除html成份 只留下純文字 var tmp = document.createElement("DIV"); tmp.innerHTML = html; return tmp.textContent||tmp.innerText; } function myReload(){ location.reload(); } function changeButtonText(text, isActive, func){//改變按鈕文字與屬性 jQuery(".delAniBabi").html("\n\t"+text+"\n\t"); jQuery(".delAniBabi")[0].childNodes[1].attributes[0].nodeValue = isActive ? "is-active" : "not-active"; if(isActive){ jQuery(".delAniBabi").click(func) } } function delMail(mailSn, date, mailContent, mailNumber){//刪除指定信件並通知 var t = jQuery, i = window.mailbox, e = mailSn; t.post("/ajax/" + i.boxType + "Del.php", "csrfToken=" + t("input[name=csrfToken]").val() + "&del[]=" + e, function(a) { if(a.code!=0){ toastr.warning("刪除第"+mailNumber+"封信ERROR:"+a.message); console.log(a); }else{ console.log(page, mailSn, "已刪除"+date+"的中獎通知:"+mailContent.replaceAll("\n","")) toastr.success("已刪除"+date+"的中獎通知"); } }, "json"); } function getMail(mailNumber){//取得信件並決定是否刪除 var t = jQuery, i = window.mailbox, e = String(myMailBox[mailNumber].substr(9, 19)), date = myDate[mailNumber]; changeButtonText("正在檢查第"+String(mailNumber)+"封信...", false) t.post({ url: "/ajax/" + window.mailbox.boxType + "Read.php", data: {sn:e},//用jsonText會出現信件編號錯誤 jsonText=JSON.stringify(json) dataType: "json", success: function(a) { if(a.code!=0){ toastr.warning("檢查第"+e+"封信ERROR:"+a.message); console.log(a); }else{ var mailContent = strip(window.mailbox.changetxt(a.data)); if(isAniBabi(mailContent)){ delMail(e, date, mailContent, mailNumber); } } if(mailNumber+1=maxMailNumber){//列表全數讀取完畢,開始讀取信件內容。 changeButtonText("正在刪除信件...", false) getMail(0); }else{//遞迴讀取下一頁的列表,不一頁頁依序讀取的話會有錯誤。 setTimeout(function(){getMailList(page+1, lastPage);}, 100); } } }) } function startDelAniBabi(){//查看所有信件 toastr.options = { positionClass: 'toast-top-center', showDuration: 60, hideDuration: 120, tapToDismiss: false }; var text = jQuery("#list_div").text(); var startPos = text.match(/[0-9]*\n封/).index, endPos = text.match(/封/).index; var totalMail = parseInt(text.substr(startPos,endPos-startPos)); jQuery(".delAniBabi").off("click") getMailList(1, Math.ceil(totalMail/20)); }; //初始化toastr通知 jQuery('head').append(''); jQuery('head').append(''); jQuery('head').append(''); //jQuery('head').append(``); /*toastr.options = { positionClass: 'toast-top-center', showDuration: 60, hideDuration: 120, tapToDismiss: false };*/ //為什麼options過一段時間會自己消失? //為什麼用jquery ready包住之後toast options的效果就會失效? (function() { /*var myShowList = window.mailbox.inbox.toString(); myShowList = myShowList.replace("e=e", "console.log\(\"456\", this.searchUser\), e = e"); myShowList = myShowList.replace("\)\)}\)}", "\), console.log\(\"123\", this.searchUser\)\)}\)}"); myShowList = myShowList.replace("t.post", "jQuery.post"); myShowList = myShowList.replace("i.page", "mailbox.page"); window.mailbox.inbox = new Function("return "+myShowList)();*/ /*把startDelAniBabi function宣告在window中 並把他放進mailbox.inbox的最後面 且將run-at設置為document-body 就可以讓系統自動執行到startDelAniBabi function */ //設置刪除中獎信按鈕 var writeMail = jQuery(".BH-menu-forumA-back"); writeMail.after(`
  • 刪除巴幣中獎信
  • `); jQuery(".delAniBabi")[0].style.marginRight = "5px"; jQuery(".delAniBabi").click(startDelAniBabi) })(); /*reference 等元素載入完畢: https://www.itread01.com/content/1545263124.html jQuery: https://ithelp.ithome.com.tw/articles/10095237 getType: http://iambigd.blogspot.com/2012/10/javascript.html html2text: https://stackoverflow.com/questions/822452/strip-html-from-text-javascript promise: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Promise https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Guide/Using_promises 正則: http://ccckmit.wikidot.com/regularexpression run-at: https://codertw.com/程式語言/709052/#outline__1_9 插入在某元素之後: https://www.w3school.com.cn/jquery/jquery_dom_add.asp 在按鈕之間插入空格: https://stackoverflow.com/questions/19769033/jquery-beginner-how-to-insert-spaces-between-append 幫元素添加css: http://www.aaronlife.com/v1/notes/html_set_css_styles_using_javascript.html 正則的global用法與match: https://blog.csdn.net/vajoy/article/details/17020423 jQuery post:https://api.jquery.com/jquery.post/ https://stackoverflow.com/questions/2833951/how-do-i-catch-an-ajax-query-post-error 串接array: https://www.w3schools.com/jsref/jsref_concat_array.asp 取消按鈕效果: https://api.jquery.com/click/ 頁面重新整理: https://ithelp.ithome.com.tw/articles/10190061 */