2014-11-07 07:24:43 -08:00
|
|
|
String.prototype.capitalize = function() {
|
|
|
|
return this.charAt(0).toUpperCase() + this.slice(1);
|
|
|
|
}
|
|
|
|
|
2014-11-07 07:06:36 -08:00
|
|
|
var lichess = {};
|
|
|
|
var serial = 0;
|
|
|
|
lichess.challenge_me = function(author, text) {
|
|
|
|
if (text == null)
|
|
|
|
text = author;
|
|
|
|
var tmp = "<a class=\"lichess_widget\" href=\"http://lichess.org/@/" + author + "\">";
|
|
|
|
tmp += "<img src=\"http://en.lichess.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />"
|
|
|
|
tmp += "<span>" + text + "</span></a>";
|
|
|
|
document.write(tmp);
|
|
|
|
};
|
|
|
|
lichess.all_scores = function(author, text) {
|
|
|
|
serial++;
|
|
|
|
var id = serial;
|
|
|
|
if (text == undefined)
|
|
|
|
text = author;
|
|
|
|
var tmp = "<a id=\"lichess_widget_" + id + "\" class=\"lichess_widget\" href=\"http://lichess.org/@/" + author + "\">";
|
|
|
|
tmp += "<img src=\"http://en.lichess.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />"
|
|
|
|
tmp += "<span>Loading...</span></a>";
|
|
|
|
document.write(tmp);
|
|
|
|
$.ajax({
|
|
|
|
url: "http://en.lichess.org/api/user/" + author,
|
|
|
|
dataType: "jsonp",
|
|
|
|
jsonp: "callback",
|
|
|
|
success: function(data) {
|
|
|
|
if (text && text != "")
|
|
|
|
text = text + " | ";
|
|
|
|
$("#lichess_widget_" + id + " > span").text(text + "Classical: " + data.perfs.classical.rating + " | Bullet: " + data.perfs.bullet.rating);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2014-11-07 07:24:43 -08:00
|
|
|
lichess.long_details = function(author, text) {
|
2014-11-07 07:06:36 -08:00
|
|
|
serial++;
|
|
|
|
var id = serial;
|
2014-11-07 07:24:43 -08:00
|
|
|
if (text == undefined)
|
|
|
|
text = author + " on Lichess";
|
|
|
|
var tmp = "<a id=\"lichess_widget_" + id + "\" class=\"lichess_widget lichess_long\" href=\"http://lichess.org/@/" + author + "\">";
|
|
|
|
tmp += "<img src=\"http://en.lichess.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />" + text + "<hr />"
|
2014-11-07 07:06:36 -08:00
|
|
|
tmp += "<span>One: two<br />Three: four</span></a>";
|
|
|
|
document.write(tmp);
|
|
|
|
$.ajax({
|
|
|
|
url: "http://en.lichess.org/api/user/" + author,
|
|
|
|
dataType: "jsonp",
|
|
|
|
jsonp: "callback",
|
|
|
|
success: function(data) {
|
2014-11-07 07:24:43 -08:00
|
|
|
var res = "";
|
|
|
|
for (var key in data.perfs) {
|
|
|
|
if (data.perfs.hasOwnProperty(key) && data.perfs[key].games > 0) {
|
|
|
|
if (res!="")
|
|
|
|
res += "<br />";
|
|
|
|
res += key.capitalize() + " rating: " + data.perfs[key].rating;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("#lichess_widget_" + id + " > span").html(res);
|
2014-11-07 07:06:36 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|