您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
自动登录HDUOJ,提供历史contests选项
当前为
// ==UserScript== // @name HDUOJ增强 // @namespace YinTianliang_i // @version 0.2.3 // @description 自动登录HDUOJ,提供历史contests选项 // @author Yin Tianliang // @include *//hdu.hustoj.com/* // @include *//acm.hdu.edu.cn/* // @include *//acm.split.hdu.edu.cn/* // @require https://code.jquery.com/jquery-3.2.1.min.js // @grant none // @run-at document-start // ==/UserScript== //alert('YES'); //console.log(window.location.toString()) //TODO:判断当前登录状态 let getCookie = (cookiename) => { return window.localStorage[cookiename]; }; let setCookie = (cname, value) => { window.localStorage[cname] = value; }; function setUserInfo() { let username = prompt("请输入用户名:"); let userpass = prompt("请输入密码:"); setCookie("username", username); setCookie("userpass", userpass); return [username, userpass]; } function contestLogin(contestID, contestPSW) { $.ajax({ type: "post", url: `http://${window.location.host}/diy/contest_login.php?cid=${contestID}&action=login`, data: { Origin: `http://${window.location.host}`, Referer: `http://${window.location.host}`, password: contestPSW }, success: function () { //alert('Login Success!'); } }); } //如果跳转到了登录界面,则开始执行逻辑 //提取url中的contestID 判断是否在cookie中 let reg = new RegExp("diy/contest_login.php.cid=(\\d+)"); let arr = window.location.toString().match(reg); if (arr) { //用户登录 let username = getCookie("username"); let userpass = getCookie("userpass"); let contestID = getCookie("contestID"); let contestPSW = getCookie("contestPSW"); if (username === undefined || userpass === undefined) { [username, userpass] = setUserInfo(); } $.ajax({ type: "post", url: `http://${window.location.host}/userloginex.php?action=login`, data: { Origin: `http://${window.location.host}`, Referer: `http://${window.location.host}`, username: username, userpass: userpass, login: "Sign In" }, success: function () { //alert('Login Success!'); } }); //单项测试登录 if (!new RegExp(arr[1]).test(contestID)) { let psw = prompt("该测试的口令未被记录,请输入该测试的口令"); if (contestID === undefined) { contestID = arr[1]; contestPSW = psw; } else { contestID += '|' + arr[1]; contestPSW += '|' + psw; } setCookie("contestID", contestID); setCookie("contestPSW", contestPSW); } contestID = contestID.split('|'); contestPSW = contestPSW.split('|'); for (let i = 0; i < contestID.length; i++) { contestLogin(contestID[i], contestPSW[i]); } //跳转到题目页面 window.location.href = `http://${window.location.host}/diy/contest_show.php?cid=${arr[1]}`; } let contestID = getCookie("contestID").split('|'); let divObj = document.createElement("div"); divObj.style = 'text-align:center'; divObj.innerHTML = '历史contests:'; for (let i in contestID) { divObj.innerHTML += `<a href="/diy/contest_show.php?cid=${contestID[i]}">${contestID[i]} </a>`; } divObj.innerHTML += '<a href="javascript:localStorage.clear();window.location.reload()">清空数据</a>'; document.body.insertBefore(divObj, document.body.firstChild);