// ==UserScript==
// @name Fast-Codeforces
// @namespace xcxxcx
// @version 0.3.4
// @match *://codeforces.com/*
// @match *://codeforc.es/*
// @match *://codeforces.ml/*
// @description Make Codeforces convenient
// @require https://code.jquery.com/jquery-3.4.1.min.js
// @author xcxxcx
// @downloadURL none
// ==/UserScript==
let $=window.$,math=unsafeWindow.MathJax.Hub,Codeforces=unsafeWindow.Codeforces;
String.prototype.frl=function(c){
if(this.indexOf(c)===-1)return this;
return this.substr(0,this.indexOf(c));
};
String.prototype.frr=function(c){
if(this.indexOf(c)===-1)return this;
return this.substr(this.indexOf(c)+c.length);
};
function obj_default(obj,val){
for(let i in val)if(!(i in obj))obj[i]=val[i];
return obj;
}
function gets(dir,val){
if(("fc-"+dir)in localStorage===false||localStorage["fc-"+dir]==="undefined")return val;
return JSON.parse(localStorage["fc-"+dir]);
}
function puts(dir,val){
if(val!==void 0)localStorage["fc-"+dir]=JSON.stringify(val);
else localStorage["fc-"+dir]="undefined";
}
function GetTitle(val){return val.substr(0,val.indexOf("")).substr(val.indexOf("
")+7);}
let version="v0.3.4",fc=obj_default(gets("fc",{}),{version:version,list:[],using:false});puts("fc",fc);
let user=$(".lang-chooser>div:eq(1)>a:eq(0)").html(),user_csrf=$("[name=X-Csrf-Token]").attr("content");
function show_pre(){$("#pageContent,#pre-bar").show();}
function hide_pre(){$("#pageContent,#pre-bar").hide();}
let menu,need=["fc","pro-user","sub-user","sta-user"];
function Clear(){
for(let i in localStorage){
if(i.substr(0,3)!=="fc-")continue;
let j=i.substr(3);console.log(j);
if(need.indexOf(j)<0)delete localStorage[i];
}
}
function default_set(){for(let i in localStorage)if(i.substr(0,3)==="fc-"&&i!=="fc-fc")delete localStorage[i];}
function add_menu(ele){
$("#fc-setting-menu-add").append(`
`);
$("#fc-setting-menu-"+ele).click(function(){let ID=this.id.substr(16);$(this).parent().remove();menu.push(ID);add_menu(ID);});
}
function set_menu(){
menu=list.slice();
$("#fc-setting-clear").before($(`
目录设置*
当前目录
剩余目录
`));
for(let i=0;i
设置
带有*的选项在修改后,需要重新加载才能生效。
Fast Codeforces版本:`+version+`
`));
for(let i=0;i=0)setTimeout(function(){get_sta(user,cnt,page,show);},sta_user.interval);
}});
}
function set_sta(){
$("#fc-setting-clear").before(`
提交记录设置
是否自动打开自己的提交记录
自动刷新间隔(不刷新为-1):毫秒
`);
if(sta_user.auto_open)$("#fc-setting-status-auto_open").attr("checked","checked");
$("#fc-setting-status-end").click(function(){
let interval=parseInt($("#fc-setting-status-interval").val());
if(typeof interval!=="number"||interval!==interval){alert("自动刷新间隔应为大于等于-1的整数");return;}
if(interval<0)interval=1;$("#fc-setting-status-interval").val(interval);
sta_user={auto_open:$("#fc-setting-status-auto_open:checked").length===1,interval:interval};puts("sta-user",sta_user);alert("修改成功");
});
}
function show_sta(){$("#fc-status").show();$("#fc-menu-status").css("background-color","#AAAAAA");}
function hide_sta(){$("#fc-status").hide();$("#fc-menu-status").css("background-color","white");}
function init_sta(){
sta_user=obj_default(gets("sta-user",{}),sta_default);puts("sta-user",sta_user);
$("#pageContent").after($(`
用户: 页码:
show unofficial
`));
$("#fc-status-stop").click(function(){++sta_cnt;clearInterval(sta_t);$("#fc-status-load").html("");});
$("#fc-status-see").click(function(){
get_sta($("#fc-status-user").val(),++sta_cnt,$("#fc-status-page").val(),$("#fc-status-show:checked").length===1);
});
if(sta_user.auto_open)get_sta(user,0);
}
function remove_sta(){$("#fc-status").remove();}
let sub_default={auto_open:true},sub_user;
function set_sub(){
$("#fc-setting-clear").before(`
提交设置
点击提交时:*
`);
$("#fc-setting-submit-auto_open>option:eq("+(sub_user.auto_open===true?0:1)+")").attr("selected","selected");
$("#fc-setting-submit-end").click(function(){
sub_user={auto_open:$("#fc-setting-submit-auto_open>option:selected").val()==="true"};puts("sub-user",sub_user);
});
}
function show_sub(){$("#fc-submit").show();$("#fc-menu-submit").css("background-color","#AAAAAA");}
function hide_sub(){$("#fc-submit").hide();$("#fc-menu-submit").css("background-color","white");}
function getsub(func){
let sub=gets("sub");
if(sub!==void 0){$("#fc-submit-form").html(sub);func();return;}
$.ajax({type:"GET",data:{},url:"/problemset/submit",error:function(e){alert("获取提交界面失败");},
success:function(e){
sub=$(e).find(".submit-form");sub.find("tr:nth-child(5)").remove();sub.find(".submit").attr("id","fc-submit-button");
sub.find(".aceEditorTd").html(` `);
sub.find("[name=submittedProblemCode]").attr("name","submittedProblemIndex");
sub=sub.html();puts("sub",sub);$("#fc-submit-form").html(sub);func();
}});
}
function init_sub(){
sub_user=obj_default(gets("sub-user",{}),sub_default);puts("sub-user",sub_user);
$("#pageContent").after($(`
`));
getsub(function(){
$("#fc-submit-button").click(function(){
$("#fc-submit .fc-care").remove();let val=$("#fc-submit [name=submittedProblemIndex]").val();
if(val===""){
$("#fc-submit .error__submittedProblemIndex").html(`Choose the problem`);return false;}
console.log(val);
let cid=parseInt(val.substr(0,val.length-1)),id=val.substr(-1);
if(cid!==cid||!id.match(/[a-zA-Z]/)){
$("#fc-submit .error__submittedProblemIndex").html(`Input a legal problem`);return false;}
if($("#fc-submit [name=source]").val()===""){
$("#fc-submit .aceEditorTd").append(`Put you source into the textarea`);return false;}
$("#fc-submit [name=submittedProblemIndex]").val(id);
if(!sub_user.auto_open||list.indexOf("status")<0){$("#fc-submit-form").attr("action",`/contest/`+cid+`/submit?csrf_token=`+user_csrf);return true;}
$.ajax({type:"POST",url:`/contest/`+cid+`/submit?csrf_token=`+user_csrf,error:function(e){alert("提交失败");return;},data:{
csrf_token:user_csrf,action:"submitSolutionFormSubmitted",submittedProblemIndex:$("#fc-submit [name=submittedProblemIndex]").val(),
programTypeId:$("#fc-submit [name=programTypeId]>option:selected").val(),source:$("#fc-submit [name=source]").val()},
success:function(e){
let sub=$(e);
if(!sub.find(`#sidebar a[href="/contest/`+cid+`"]`).length){alert("该题目不存在!");return;}
if(sub.find(".error.for__source").length){alert("您已经提交过相同的代码!");return;}
if(GetTitle(e).substr(0,6)!=="Status"){alert("该题目不存在!");return;}
}
});
return false;
Change("status");$("#fc-status-user").val(user);$("#fc-status-page").val(1);$("#fc-status-show").attr("checked","checked");
$("#fc-status-see").click();document.documentElement.scrollTop=0;return false;
});});
}
function remove_sub(){$("#fc-submit").remove();}
let pro_default={mem:0,auto_open:false},pro_user,prepro,prolist,focpro,promap={};
function set_pro(){
$("#fc-setting-clear").before($(`
题目设置
上一次未关闭的题目是否打开:
点击题目链接时在"查看题目"中将其打开*
`));
if(pro_user.auto_open)$("#fc-setting-problem-auto_open").attr("checked","checked");
$("#fc-setting-problem-end").click(function(){
pro_user={mem:$("#fc-setting-problem-memory>option:selected").val(),auto_open:$("#fc-setting-problem-auto_open:checked").length===1};
puts("pro-user",pro_user);alert("修改成功");
});
$("#fc-setting-problem-memory>option:eq("+pro_user.mem+")").attr("selected","selected");
}
function showpro(ID){$("#fc-problem-menu-"+ID).addClass("focpro");$("#fc-problem-"+ID+",#fc-bar-problem-"+ID).show();}
function hidepro(ID){$("#fc-problem-menu-"+ID).removeClass("focpro");$("#fc-problem-"+ID+",#fc-bar-problem-"+ID).hide();}
function show_pro(){$("#fc-problem,#fc-bar-problem").show();$("#fc-menu-problem").css("background-color","#AAAAAA");}
function hide_pro(){$("#fc-problem,#fc-bar-problem").hide();$("#fc-menu-problem").css("background-color","white");}
function addpro(x,y){
let load=$(`
`),loadstr="";
promap[x+y]=1;$("#fc-problem-menu").append(load);
let t=setInterval(function(){loadstr=loadstr.length===2?"":loadstr+".";load.find("a").html("Loading "+x+y+loadstr);},400);
$.ajax({type:"GET",data:{},url:"/contest/"+x+"/problem/"+y,error:function(e){clearInterval(t);load.remove();alert("出错了!");},
success:function(e){
clearInterval(t);load.remove();
let pro=$(e),title=GetTitle(e);
if((title!=="Problem - "+y+" - Codeforces (Unofficial mirror site by GGAutomaton, accelerated for Chinese users)"&&title!=="Problem - "+y+
" - Codeforces")||!pro.find(`#sidebar a[href="/contest/`+x+`"]`).length){delete promap[x+y];alert("题目"+x+y+"不存在");return;}
x+=y;pro=[pro.find(`.problem-statement`),pro.find(`#sidebar`)];promap[x]=0;
$("#fc-problem-menu-add").before(`