Tweek long widget

master
rubenwardy 2014-11-07 15:24:43 +00:00
parent 808343e2ac
commit 44187c4450
3 changed files with 39 additions and 6 deletions

View File

@ -6,7 +6,8 @@
border: 1px solid #444;
padding: 5px 7px 7px 5px;
color: #e0e0e0;
border-radius:4px;
border-radius: 4px;
text-decoration: none;
}
.lichess_widget:hover {
background: #4A4A4A;
@ -25,3 +26,10 @@
.lichess_long {
width: 200px;
}
.lichess_long hr {
margin: 6px 0 2px 0;
background: #666;
border: none;
height: 1px
}

View File

@ -34,7 +34,7 @@
</style>
</head>
<body>
<h1>(Work in progress) Widgets for Lichess</h1>
<h1>Widgets for Lichess (Work in progress)</h1>
<p>
Add the following to the &lt;head&gt; of your webpage,
@ -98,4 +98,15 @@
</blockcode>
</td>
</tr>
<tr>
<td>
<script>lichess.long_details("rubenwardy", "My Lichess");</script>
</td>
<td>
<blockcode>
&lt;script&gt;lichess.long_details("rubenwardy", "My Lichess");&lt;/script&gt;
</blockcode>
</td>
</tr>
</table>

View File

@ -1,3 +1,7 @@
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
var lichess = {};
var serial = 0;
lichess.challenge_me = function(author, text) {
@ -28,11 +32,13 @@ lichess.all_scores = function(author, text) {
}
});
};
lichess.long_details = function(author) {
lichess.long_details = function(author, text) {
serial++;
var id = serial;
var tmp = "<a id=\"lichess_long_" + author + "\" 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\" />Lichess<br /><br />"
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 />"
tmp += "<span>One: two<br />Three: four</span></a>";
document.write(tmp);
$.ajax({
@ -40,7 +46,15 @@ lichess.long_details = function(author) {
dataType: "jsonp",
jsonp: "callback",
success: function(data) {
$("#lichess_widget_" + id + " > span").text(author + "<br />Classical: " + data.perfs.classical.rating + "<br />Bullet: " + data.perfs.bullet.rating);
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);
}
});
};