Skip to content

Instantly share code, notes, and snippets.

@neetsdkasu
Last active March 19, 2019 16:05
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/6475f975f37ef0b1cda36d2721426fe2 to your computer and use it in GitHub Desktop.
Save neetsdkasu/6475f975f37ef0b1cda36d2721426fe2 to your computer and use it in GitHub Desktop.
show max rating on Topcoder MarathonMatch standings
{
"manifest_version": 2,
"name": "show max rating on Topcoder MarathonMatch standings",
"version": "1.0",
"author": "Leonardone",
"description": "show max rating on Topcoder MarathonMatch standings",
"content_scripts": [
{
"matches": ["*://community.topcoder.com/longcontest/*"],
"include_globs": ["*ViewStandings*", "*ViewOverview*"],
"js": ["script.js"]
}
]
}
// script.js
// Browser WebExtention
// show max rating on Topcoder MarathonMatch standings
// author: Leonardone
(function() {
// start of coder
var elms = document.getElementsByTagName('a');
var coders = [];
for (i = 0; i < elms.length; i++) {
var e = elms[i];
var cn = e.className.toString();
if (!cn.match(/coderText\w+/)) {
continue;
}
var c = coders.length;
coders[c] = e;
}
var xhr = (function() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
try {
return new ActiveXObject('Microsoft.XMLHTTP');
} catch (_) {}
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch (_) {}
}
return {
'open': function() {},
'send': function() {}
};
})();
function getUserInfo(i) {
var e = coders[i];
var href = e.href.toString();
var m = href.match(/cr=(\d+)/);
var id = m[1];
var name = e.innerHTML.toString();
return {
"id": id,
"name": name
};
}
function getCoderClass(r) {
if (r >= 2200) {
return 'coderTextRed';
} else if (r >= 1500) {
return 'coderTextYellow';
} else if (r >= 1200) {
return 'coderTextBlue';
} else if (r >= 900) {
return 'coderTextGreen';
} else if (r >= 0) {
return 'coderTextGray';
} else {
return 'coderTextBlack';
}
}
function parse(n, xml) {
var maxRating = -1;
var lastDate = '1900-01-01';
var lastRating = -1;
var rs = xml.getElementsByTagName('row');
for (var j = 0; j < rs.length; j++) {
var es = rs[j].getElementsByTagName('new_rating');
var rt = parseInt(es[0].innerHTML.toString());
maxRating = Math.max(maxRating, rt);
var ds = rs[j].getElementsByTagName('date');
var dt = ds[0].innerHTML.toString();
if (dt > lastDate) {
lastDate = dt;
lastRating = rt;
}
}
var s3 = document.createElement('span');
s3.className = getCoderClass(maxRating);
maxRating = Math.max(0, maxRating);
s3.innerHTML = '&nbsp;(' + maxRating.toString() + ')';
coders[n].appendChild(s3);
coders[n].title = 'now: ' + lastRating.toString() + ', max:' + maxRating.toString();
}
function load(i) {
var interval = 1000; // milliseconds
if (i >= coders.length) {
return;
}
xhr.onreadystatechange = function() {
if (xhr.readyState !== 4) { return; }
if (xhr.status !== 200) {
return;
}
var xml = xhr.responseXML;
parse(i, xml);
window.setTimeout(function() {
load(i+1);
}, interval);
};
var info = getUserInfo(i);
var protocol = 'https';
var server = 'community.topcoder.com';
var command = 'tc?module=BasicData&c=dd_marathon_rating_history&cr=';
var url = protocol + '://' + server + '/' + command + info.id;
xhr.open('GET', url, true);
xhr.responseType = 'document';
if (xhr.setRequestHeader) {
xhr.setRequestHeader('Content-type', 'text/xml');
}
xhr.overrideMimeType = 'text/xml';
xhr.send(null);
}
load(0);
// end of code
})();
@neetsdkasu
Copy link
Author

neetsdkasu commented Mar 9, 2019

FireFoxだとこれちゃんと機能しないね・・・(いあ他のブラウザでもちゃんと動くかは未確認?
アドオン再読込をクリックしたのが原因ぽい?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment