You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.8 KiB

  1. function toggleLeaderBoard(){
  2. var leaderBoard = document.getElementById("leaderBoard");
  3. if( hasClass(leaderBoard, "open")){
  4. removeClass(leaderBoard, "open");
  5. }else{
  6. leaderBoard.className += " open";
  7. }
  8. updateLeaderBoard()
  9. }
  10. function populateBoard(){
  11. var listBoard = document.getElementById("listBoard");
  12. var results = "";
  13. var rankings = data.data.rankings;
  14. var date = new Date();
  15. var seconds = date.getSeconds();
  16. var minutes = date.getMinutes();
  17. var hour = date.getHours();
  18. var leaderBoardServerJson = {};
  19. leaderBoardServerJson.timeStamp = date.getTime();
  20. for (var i = rankings.length - 1; i >= 0; i--) {
  21. if( rankings[i].teamId == 235 ){
  22. results += "<p>Updated "+hour+"h "+minutes+"m "+seconds+"s</p>";
  23. results += "<h1>Cazziammolla Placement: "+rankings[i].rank+"</h1>";
  24. results += "<h2>with a score of: "+rankings[i].score+"</h2>";
  25. leaderBoardServerJson.placement = rankings[i].rank;
  26. leaderBoardServerJson.score = rankings[i].score;
  27. if (rankings[i].rank != points && points != 0){
  28. ringTheBell();
  29. }
  30. points = rankings[i].rank;
  31. }
  32. };
  33. leaderBoardServerJson.settings = [];
  34. var settings = data.data.settings;
  35. for (var i = 0; i < settings.length; i++) {
  36. for (var j = settings[i].rankings.length - 1; j >= 0; j--) {
  37. if(settings[i].rankings[j].teamId == 235){
  38. results += "<tr><td>"+i+"</td><td>"+settings[i].rankings[j].rank+"</td><td>"+settings[i].rankings[j].score+"</td></tr>"
  39. leaderBoardServerJson.settings[i] = { rank: settings[i].rankings[j].rank, score: settings[i].rankings[j].score};
  40. }
  41. };
  42. };
  43. var results = "<table><thead><th>Setting</th><th>Placement</th><th>Score</th></thead>"+results+"</table>";
  44. listBoard.innerHTML = results;
  45. try{
  46. socket.emit('leaderBoard', JSON.stringify( leaderBoardServerJson));
  47. }catch(e){
  48. console.log("error");
  49. }
  50. }
  51. function updateLeaderBoard(){
  52. loadRankingJs('https://davar.icfpcontest.org/rankings.js?cachebuster='+ new Date().getTime());
  53. var intervalID = setInterval( function(){
  54. loadRankingJs('https://davar.icfpcontest.org/rankings.js?cachebuster='+ new Date().getTime());
  55. }, 30000);
  56. }
  57. function loadRankingJs(scriptName) {
  58. var rankingScript = document.getElementById("rankingScript");
  59. if ( rankingScript ){
  60. removeId("rankingScript");
  61. }
  62. var docHeadObj = document.getElementsByTagName("head")[0];
  63. var dynamicScript = document.createElement("script");
  64. dynamicScript.type = "text/javascript";
  65. dynamicScript.id = "rankingScript";
  66. dynamicScript.src = scriptName;
  67. dynamicScript.onload = function(){ populateBoard();};
  68. docHeadObj.appendChild(dynamicScript);
  69. return dynamicScript;
  70. }
  71. function ringTheBell(){
  72. document.getElementById("bell").play();
  73. }
  74. document.onkeydown = checkKey;
  75. function checkKey(e) {
  76. e = e || window.event;
  77. if (e.keyCode == '37') {
  78. slideBack();
  79. }else if(e.keyCode == '39') {
  80. slideForward();
  81. }
  82. }