Better Games Done Quick Schedule

Adds infos about the current Run to the top of the page, a link that brings you down to the current run in the Shedule, a countdown to the next Run and an auto refresh for when the next run is estimated to start, so thta you have always the correct times and runs displayed and highlighted

当前为 2017-01-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Better Games Done Quick Schedule
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.2
  5. // @description Adds infos about the current Run to the top of the page, a link that brings you down to the current run in the Shedule, a countdown to the next Run and an auto refresh for when the next run is estimated to start, so thta you have always the correct times and runs displayed and highlighted
  6. // @author Ruben
  7. // @match https://gamesdonequick.com/schedule
  8. // @grant none
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. console.log("Better AGDQ Shedule loading...");
  16. var tableRows = $("#runTable tbody tr").not(".day-split");
  17. var tableRowsDays = $("#runTable tbody tr");
  18. var time = "";
  19. var day = 0;
  20. var currentDate = new Date($.now());
  21. var rowOfCurrentRun = 0;
  22. var refreshInSeconds = 0;
  23. var refreshInTime = "";
  24. var newDate;
  25. var countdown;
  26. var days = {};
  27. var amountOfDays = 0;
  28. var counter = 0;
  29. console.log("Collecting and formatting dates and times...");
  30. for(var j = 0; j < tableRowsDays.length; j = j + 2)
  31. {
  32. if(tableRowsDays.eq(j).hasClass("day-split"))
  33. {
  34. day = tableRowsDays.eq(j).text().match(/\d+/)[0];
  35. //console.log(day);
  36. j--;
  37. continue;
  38. }
  39. //console.log(tableRowsDays.eq(j));
  40. days.length = amountOfDays+1;
  41. days[amountOfDays] = day;
  42. //console.log(days);
  43. amountOfDays++;
  44. }
  45. for(var i = 0; i < tableRows.length; i = i + 2)
  46. {
  47. time = timeFormatting(tableRows.eq(i).children().eq(0).text());
  48. //console.log(days[counter]);
  49. var date="2017/01/" + days[counter] +" " + time;
  50. newDate = new Date(Date.parse(date));
  51. //newDate = newDate -(-6000000);
  52. if(currentDate < newDate)
  53. {
  54. console.log("Highlighting current runs...");
  55. //console.log(newDate);
  56. //console.log(currentDate);
  57. //console.log(tableRows.eq(i-2));
  58. //console.log(tableRows.eq(i-1));
  59. //Ändere Background vom vorheriger Run
  60. tableRows.eq(i-4).css("background-color", "#f2dede");
  61. tableRows.eq(i-4).css("color", "black");
  62. tableRows.eq(i-3).css("background-color", "#f2dede");
  63. tableRows.eq(i-3).css("color", "black");
  64. $(tableRows.eq(i-4)).attr('id', 'currentRun');
  65. //Ändere Background vom aktuellem Run
  66. tableRows.eq(i-2).css("background-color", "#a00303");
  67. tableRows.eq(i-2).css("color", "white");
  68. tableRows.eq(i-1).css("background-color", "#a00303");
  69. tableRows.eq(i-1).css("color", "white");
  70. //Ändere Background vom nächsten Run
  71. tableRows.eq(i).css("background-color", "#f2dede");
  72. tableRows.eq(i).css("color", "black");
  73. tableRows.eq(i+1).css("background-color", "#f2dede");
  74. tableRows.eq(i+1).css("color", "black");
  75. rowOfCurrentRun = i;
  76. i = tableRows.length;
  77. }
  78. counter++;
  79. }
  80. console.log("Adding current run to the top of the page...");
  81. //Den aktuellen RUN an den Anfang der Seite einfügen
  82. var top = $(tableRows.eq(rowOfCurrentRun-2)).children();
  83. var bottom = $(tableRows.eq(rowOfCurrentRun-1)).children();
  84. refreshInSeconds = Math.ceil(((newDate - currentDate)/1000));
  85. refreshInTime = secondsToTime(refreshInSeconds);
  86. var countdown = "<div id='countdown' style='display: inline-block; text-align: center; padding: 5px 20px; line-height: 25px; background-color: #a00303; color: white; width: 150px; height: 100%'>Next Run in: " + refreshInTime + "</div>";
  87. var goToCurrentRun = "<a href='#currentRun' id='goToCurrentRun' style='display: inline-block; text-align: center; padding: 5px 20px; color: white; line-height: 25px; padding-left: 15px; height: 100%; width: 150px; text-decoration: none; background-color: #8c1616;'>Go to Current Run <img style='filter: invert(); width: 20px; height: 22px' src='https://cdn0.iconfinder.com/data/icons/navigation-set-arrows-part-one/32/DoubleChevronDown-128.png'/></a>";
  88. var currentRun = "<div style='overflow-x: auto; display: inline-block; max-width: 100%; vertical-align: top;'><nobr><div style='background-color: #a00303; color: white; padding: 5px 20px; line-height: 25px; display: inline-block;'>Current Run: <b>" + top.eq(1).text() + " (" + bottom.eq(1).text() + ")</b>&emsp;From: <b>" + top.eq(2).text() + "</b><br/>Start: <b>" + timeFormatting(top.eq(0).text()) + "&emsp;</b> Duration: <b>" + timeFormatting(bottom.eq(0).text()) + "&emsp;</b> Setup Length: <b>" + timeFormatting(top.eq(3).text()) + "</b></div></nobr></div>" + goToCurrentRun + countdown;
  89.  
  90. $("<li><a style='padding-left: 25px; padding-right: 5px'><label><input style='margin-right: 11px' type='checkbox' name='checkbox' " + getCookieCheckbox() + "/>Auto Refresh</label></a></li>").insertAfter(".nav.navbar-nav li:first-child ul li:last-child");
  91. $("#top").after(currentRun);
  92. //console.log($("#white-bg").eq(2));
  93. $("#goToCurrentRun").mouseenter(function() {
  94. $(this).css("background-color", "#c32323");
  95. }).mouseleave(function() {
  96. $(this).css("background-color", "#8c1616");
  97. });
  98. countdown = setInterval(function() {
  99. refreshInSeconds--;
  100. if(Math.ceil(((newDate - new Date($.now()))/1000)) < 0) {
  101. clearInterval(countdown);
  102. if(getCookie('autoRefresh') == "true") location.reload();
  103. } else {
  104. $("#countdown").text("Next Run in: "+secondsToTime(Math.ceil(((newDate - new Date($.now()))/1000))));
  105. }
  106. }, 1000);
  107. console.log("Better AGDQ Shedule done");
  108. })();
  109.  
  110. function timeFormatting(time)
  111. {
  112. //console.log("TimeFormatting:" + time);
  113. //console.log("Länge: " + time.length);
  114. //console.log(time);
  115. if(time.length == 7)
  116. {
  117. time = "0" + time;
  118. }
  119. else if(time.length == 10)
  120. {
  121. time = time.replace(/ /g, "0");
  122. }
  123. else
  124. {
  125. time = time;
  126. }
  127. return time;
  128. }
  129.  
  130. function secondsToTime(seconds)
  131. {
  132. var hours = Math.floor((seconds/60/60));
  133. seconds = seconds - hours*60*60;
  134. var minutes = Math.floor((seconds/60));
  135. seconds = seconds - minutes*60;
  136. return(addZero(hours) + ":" + addZero(minutes) + ":" + addZero(seconds));
  137. }
  138.  
  139. function addZero(time)
  140. {
  141. if(time.toString().length == 1)
  142. {
  143. return ("0" + time);
  144. }
  145. else return ("" + time);
  146. }
  147.  
  148. function setCookie(cname, cvalue, exdays) {
  149. var d = new Date();
  150. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  151. var expires = "expires="+ d.toUTCString();
  152. document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  153. }
  154.  
  155. function getCookie(cname) {
  156. var name = cname + "=";
  157. var decodedCookie = decodeURIComponent(document.cookie);
  158. var ca = decodedCookie.split(';');
  159. for(var i = 0; i <ca.length; i++) {
  160. var c = ca[i];
  161. while (c.charAt(0) == ' ') {
  162. c = c.substring(1);
  163. }
  164. if (c.indexOf(name) == 0) {
  165. return c.substring(name.length, c.length);
  166. }
  167. }
  168. return "";
  169. }
  170.  
  171. function getCookieCheckbox()
  172. {
  173. if(getCookie('autoRefresh') == "true") return "checked";
  174. }
  175.  
  176. $('input:checkbox').change(
  177. function(){
  178. if ($(this).is(':checked')) {
  179. setCookie('autoRefresh', true, 30);
  180. }
  181. else {
  182. setCookie('autoRefresh', false, 30);
  183. }
  184. });