// ==UserScript== // @name Fast-Codeforces // @namespace xcxxcx // @version 0.2.4 // @match *://codeforces.com/* // @match *://codeforc.es/* // @match *://codeforces.ml/* // @description 使您更方便地使用Codeforces // @require https://code.jquery.com/jquery-3.4.1.min.js // @author xcxxcx // @downloadURL none // ==/UserScript== var $=unsafeWindow.jQuery,math=unsafeWindow.MathJax,JPar=JSON.parse,JStr=JSON.stringify; var tcount=[],tsum=0; function empty(){} function gets(dir){ if(("fc-"+dir) in localStorage ===false||localStorage["fc-"+dir]==="undefined")return void 0; return JPar(localStorage["fc-"+dir]); } function puts(dir,val){ if(val!==void 0)localStorage["fc-"+dir]=JStr(val); else localStorage["fc-"+dir]="undefined"; } var user=$(".lang-chooser>div:eq(1)>a:eq(0)").html(),user_csrf=$("[name=X-Csrf-Token]").attr("content"); function Ajax(url){ var tmp=++tsum; $.ajax({ method:"GET",url:url,data:{},success:function(e){tcount[tmp]=e;}, error:function(e){tcount[tmp]="Err";} }); return tmp; } function Get(url){ return $.ajax({ async:false,method:"GET",url:url,data:{},success:function(e){return e;}, error:function(e){return e;} }).responseText; } function show_pre(){$("#pageContent,#pre-bar").show();} function hide_pre(){$("#pageContent,#pre-bar").hide();} function show_set(){$("#fc-setting").show();$("#fc-menu-setting").css("background-color","#AAAAAA");} function hide_set(){$("#fc-setting").hide();$("#fc-menu-setting").css("background-color","white");} function init_set(){ $("#pageContent").after($(` `)); for(var i=0;i`); puts("submit",sub.html());$("#fc-submit-form").html(sub.html()); } function init_sub(){ $("#pageContent").after($(``)); getsub(); } var pro_default={mem:0},pro_user,prepro,prolist=[],focpro,promap={}; function sets_pro(){ $("#fc-setting .header").after($(`
题目设置

上一次未关闭的题目是否记录下来,是否自动打开:

`)); $("#fc-setting-problem-memory>option:eq("+pro_user.mem+")").attr("selected","selected"); } function setc_pro(){ pro_user.mem=$("#fc-setting-problem-memory>option:selected").val(); puts("pro-user",pro_user); } 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){ var tmp=Ajax("/problemset/problem/"+x+"/"+y,true),load=$(`
  • `),loadstr=""; x+=y;promap[x]=1;$("#fc-problem-menu").append(load); var t=setInterval(function(){ loadstr=loadstr.length===2?"":loadstr+".";load.find("a").html("Loading "+x+loadstr); if(tcount[tmp]===void 0)return; load.remove(); if(tcount[tmp]==="Err"){delete promap[x];alert("添加题目"+x+"失败");} var pro=$(tcount[tmp]),len=pro.length,title; for(var i=0;i`+x+`X`); var node=$("#fc-problem-menu-"+x).children(); $(node[0]).click(function(){ if(focpro!==void 0)hidepro(focpro); showpro(this.innerHTML);focpro=this.innerHTML; }); $(node[1]).click(function(){ var fa=$(this).parent(),ID=fa.children()[0].innerHTML,pos=prolist.indexOf(ID); delete promap[prolist[pos]];prolist.splice(pos,1); if(focpro===ID){ prolist.splice(pos,1); if(pos===prolist.length)--pos; if(pos!==-1){focpro=prolist[pos];showpro(focpro);} else focpro=void 0; } fa.remove();$("#fc-problem-"+ID).remove();puts("pro-list",prolist); }); $("#fc-problem-contain").append(pro[0].attr("id","fc-problem-"+x)); $("#fc-bar-problem").append(pro[1].attr("id","fc-bar-problem-"+x)); if(focpro!==void 0)hidepro(focpro); showpro(x);prolist.push(focpro=x);math.Hub.Queue(["Typeset",math.Hub,"fc-problem-"+x]);puts("pro-list",prolist); },400); } function newpro(ID){ if(ID===""||ID===null)return; if(typeof ID!=="string"){alert("请输入正确的题号");return;} if(promap[ID]===0){alert("该题目已在序列中");return;} if(promap[ID]===1){alert("该题目正在添加中");return;} var pnum=ID.substr(ID.length-1),pl=parseFloat(ID.substr(0,ID.length-1)); if(parseInt(pl)!==pl){alert("请输入正确的题号");return;} addpro(pl,pnum); } function init_pro(){ pro_user=gets("pro-user"); if(pro_user===void 0){pro_user=pro_default;puts("pro-user",pro_user);puts("pro-list",[]);} prepro=gets("pro-list"); $("#pageContent").after($(``)); $("#fc-problem-menu-close").click(function(){Change("problem");}); $("#fc-problem-menu-add").hover(function(){ var x=$("#fc-problem-menu>.backLava"); if(x.length>0)x.remove(); }); var link=$("link"),sideCSS=false,statCSS=false; for(var i=0;i`)); if(!statCSS)$("head").append($(``)); $("#fc-bar-menu").after(``);$("#fc-problem-menu-add").click(function(){newpro(prompt());}); if(pro_user.mem==2||(pro_user.mem==1&&prepro.length>0&&confirm("您上次浏览的题目未关闭,确定重新加载吗?"))){ for(var j=0;j开始使用Fast Codeforces`); $("#fc-start").click(function(){ if(confirm("Fast Codeforces需要使用您的CSRF-token,您确定要授权吗?")===false)return; puts("using",true);alert("授权成功");showMain(); }); } function showMain(){ $("#fc-menu").html(`停止使用Fast Codeforces`); $("#fc-stop").click(function(){ if(confirm("您确认要停止使用Fast Codeforces?")===false)return; puts("using",false);alert("Fast Codeforces已停止");showLogin();$("#fc-problem").remove();$("#fc-submit").remove(); }); for(var i=0;i`+obj.name+`
    `)); $("#fc-menu-"+id).click(function(){Change($(this).attr("id").substr(8));}); } $(document).ready(function(){ if($("#sidebar").length===0)return; var sidebar=$("#sidebar").html(); $("#sidebar").html(`
    `+sidebar+`
    `); if($(".header-bell").length===0)$("#fc-menu").html(`请登录后再使用!`); else if(gets("using"))showMain(); else showLogin(); });