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;
|
2014-11-07 07:40:39 -08:00
|
|
|
|
|
|
|
lichess.__make_online = function(id) {
|
|
|
|
$(id).addClass("lichess_online");
|
|
|
|
$(id + " > img").attr("src", "http://rubenwardy.github.io/lichess_widgets/lichess_online.png");
|
|
|
|
}
|
|
|
|
|
2014-11-07 08:33:38 -08:00
|
|
|
lichess.profile = function(theme, author, text) {
|
2014-11-07 07:40:39 -08:00
|
|
|
serial++;
|
|
|
|
var id = serial;
|
2014-11-07 07:06:36 -08:00
|
|
|
if (text == null)
|
|
|
|
text = author;
|
2014-11-07 08:33:38 -08:00
|
|
|
var tmp = "<a id=\"lichess_widget_" + id + "\" class=\"lichess_widget lichess_theme_" + theme + "\" href=\"http://lichess.org/@/" + author + "\">";
|
2014-11-07 07:06:36 -08:00
|
|
|
tmp += "<img src=\"http://en.lichess.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />"
|
|
|
|
tmp += "<span>" + text + "</span></a>";
|
|
|
|
document.write(tmp);
|
2014-11-07 07:40:39 -08:00
|
|
|
$.ajax({
|
|
|
|
url: "http://en.lichess.org/api/user/" + author,
|
|
|
|
dataType: "jsonp",
|
|
|
|
jsonp: "callback",
|
|
|
|
success: function(data) {
|
|
|
|
if (data.online)
|
|
|
|
lichess.__make_online("#lichess_widget_" + id);
|
|
|
|
}
|
|
|
|
});
|
2014-11-07 07:06:36 -08:00
|
|
|
};
|
2014-11-07 08:33:38 -08:00
|
|
|
lichess.profile_scores = function(theme, author, text) {
|
2014-11-07 07:06:36 -08:00
|
|
|
serial++;
|
|
|
|
var id = serial;
|
|
|
|
if (text == undefined)
|
|
|
|
text = author;
|
2014-11-07 08:33:38 -08:00
|
|
|
var tmp = "<a id=\"lichess_widget_" + id + "\" class=\"lichess_widget lichess_theme_" + theme + "\" href=\"http://lichess.org/@/" + author + "\">";
|
2014-11-07 07:06:36 -08:00
|
|
|
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) {
|
2014-11-07 07:40:39 -08:00
|
|
|
if (data.online)
|
|
|
|
lichess.__make_online("#lichess_widget_" + id);
|
|
|
|
|
2014-11-07 07:06:36 -08:00
|
|
|
if (text && text != "")
|
|
|
|
text = text + " | ";
|
2014-11-07 07:49:37 -08:00
|
|
|
$("#lichess_widget_" + id + " > span").html(text + "Classical <b>" + data.perfs.classical.rating + "</b> | Bullet <b>" + data.perfs.bullet.rating + "</b>");
|
2014-11-07 07:06:36 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2014-11-07 08:33:38 -08:00
|
|
|
lichess.profile_big = function(theme, 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";
|
2014-11-07 08:33:38 -08:00
|
|
|
var tmp = "<a id=\"lichess_widget_" + id + "\" class=\"lichess_widget lichess_theme_" + theme + " lichess_long\" href=\"http://lichess.org/@/" + author + "\">";
|
2014-11-07 07:24:43 -08:00
|
|
|
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:40:39 -08:00
|
|
|
if (data.online)
|
|
|
|
lichess.__make_online("#lichess_widget_" + id);
|
|
|
|
|
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 />";
|
2014-11-07 07:49:37 -08:00
|
|
|
res += key.capitalize() + " <b>" + data.perfs[key].rating + "</b> / " + data.perfs[key].games + " Games";
|
2014-11-07 07:24:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$("#lichess_widget_" + id + " > span").html(res);
|
2014-11-07 07:06:36 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|