// ==UserScript==
// @name Codeforces Problem Submit Helper
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Fetches the current Codeforces URL, and parses it for the problem identifier and automatically puts it in the field that asks for it.
// @author SirRogue
// @match *://codeforces.com/*
// @match *://www.codeforces.com/*
// @run-at document-idle
// ==/UserScript==
(function(){
'use strict';
const currenturl=window.location.href;
function extractproblemidentifier(urlstr){
if(!urlstr){
return null;
}
const problemset=/problemset\/problem\/(\d+)\/([A-Za-z0-9]+)/i;
const match=urlstr.match(problemset);
if(match){
return match[1]+match[2].toUpperCase();
}
return null;
}
const problemidentifier=extractproblemidentifier(currenturl);
if(problemidentifier){
localStorage.setItem('problemidentifier',problemidentifier);
return;
}
if(/\/problemset\/submit\b/.test(currenturl)){
const savedproblemidentifier=localStorage.getItem('problemidentifier');
if(!savedproblemidentifier){
return;
}
const input=
document.querySelector('input[name="submittedProblemCode"]')||
document.querySelector('input[name="submittedProblemIndex"]')||
document.querySelector('input[type="text"]');
if(input){
input.value=savedproblemidentifier;
input.dispatchEvent(new Event('input',{bubbles:true}));
input.dispatchEvent(new Event('change',{bubbles:true}));
}
}
})();