Skip to content

Instantly share code, notes, and snippets.

@neetsdkasu
Last active March 7, 2019 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neetsdkasu/4c7d87a5f64b4f4195cb732bee23a8b5 to your computer and use it in GitHub Desktop.
Save neetsdkasu/4c7d87a5f64b4f4195cb732bee23a8b5 to your computer and use it in GitHub Desktop.
add user data link on Topcoder MarathonMatch standings
{
"manifest_version": 2,
"name": "add user data link on Topcoder MarathonMatch standings",
"version": "1.0",
"author": "Leonardone",
"description": "add user data link on Topcoder MarathonMatch standings",
"content_scripts": [
{
"matches": ["*://community.topcoder.com/longcontest/*"],
"include_globs": ["*ViewStandings*", "*ViewOverview*"],
"js": ["script.js"]
}
]
}
// script.js
// Browser WebExtention
// add user data link on Topcoder MarathonMatch standings
// author: Leonardone
(function() {
// start of code
var protocol = 'https';
var server = 'community.topcoder.com';
var mmHistory = 'tc?module=SimpleStats&c=long_comp_history&d1=statistics&d2=longHistory&cr=';
var algoHistory = 'tc?module=AlgoCompetitionHistory&cr=';
var paymentSummary = 'tc?module=PaymentSummary&cr=';
var achievements = 'tc?module=SimpleStats&c=coder_achievements&d1=statistics&d2=coderAchievements&cr=';
var exampleResults = 'longcontest/?module=ViewExampleResults&pm=PM&rd=RD&cr=';
function getMMHistoryUrl(id, pm, rd) {
return protocol + '://' + server + '/' + mmHistory + id;
}
function getAlgoHistoryUrl(id, pm, rd) {
return protocol + '://' + server + '/' + algoHistory + id;
}
function getPaymentSummaryUrl(id, pm, rd) {
return protocol + '://' + server + '/' + paymentSummary + id;
}
function getAchievementsUrl(id, pm, rd) {
return protocol + '://' + server + '/' + achievements + id;
}
function getExampleResultsUrl(id, pm, rd) {
var cmd = exampleResults.replace('PM', pm).replace('RD', rd);
return protocol + '://' + server + '/' + cmd + id;
}
var texts = ['Example Results', 'MM history', 'Algo history', 'Achievements', 'Payment summary'];
var funcs = [getExampleResultsUrl, getMMHistoryUrl, getAlgoHistoryUrl, getAchievementsUrl, getPaymentSummaryUrl];
var coders = [];
var rd = '';
var pm = '';
var elms = document.getElementsByTagName('a');
for (i = 0; i < elms.length; i++) {
var e = elms[i];
var cn = e.className.toString();
if (!cn.match(/coderText\w+/)) {
var href = e.href.toString();
if (href.indexOf('ViewProblemStatement') >= 0) {
var ms = href.match(/pm=(\d+)/);
if (ms) {
pm = ms[1];
}
ms = href.match(/rd=(\d+)/);
if (ms) {
rd = ms[1];
}
}
continue;
}
var id = e.href.toString().match(/cr=(\d+)/)[1];
var a = document.createElement('a');
a.href = funcs[0](id, pm, rd);
a.target = '_blank';
a.innerHTML = '&nbsp;link';
e.parentNode.appendChild(a);
var c = coders.length;
coders[c] = [id, a];
}
var showType = 0;
var tbhs = document.getElementsByClassName('statTableHolder');
if (tbhs.length !== 1) {
tbhs = document.getElementsByClassName('stat');
if (tbhs.length !== 1) {
alert('failed webextention');
return;
}
}
var tbh = tbhs[0];
var tbhp = tbh.parentNode;
var cont = document.createElement('div');
var btn = document.createElement('input');
btn.type = 'button';
btn.value = 'switch';
cont.appendChild(btn);
var span = document.createElement('span');
span.innerHTML = '&nbsp;link is ' + texts[0];
cont.appendChild(span);
tbhp.insertBefore(cont, tbh);
btn.onclick = function() {
showType = (showType + 1) % Math.min(texts.length, funcs.length);
var f = funcs[showType];
for (var j = 0; j < coders.length; j++) {
coders[j][1].href = f(coders[j][0], pm, rd);
}
span.innerHTML = '&nbsp;link is ' + texts[showType];
};
// end of code
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment