Better Games Done Quick Schedule

try to take over the world!

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

  1. // ==UserScript==
  2. // @name Better Games Done Quick Schedule
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0
  5. // @description try to take over the world!
  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. $("#top").after(currentRun);
  91. //console.log($("#white-bg").eq(2));
  92. $("#goToCurrentRun").mouseenter(function() {
  93. $(this).css("background-color", "#c32323");
  94. }).mouseleave(function() {
  95. $(this).css("background-color", "#8c1616");
  96. });
  97. countdown = setInterval(function() {
  98. refreshInSeconds--;
  99. if(refreshInSeconds < 0) {
  100. //Refresh
  101. clearInterval(countdown);
  102. } else {
  103. $("#countdown").text("Next Run in: "+secondsToTime(refreshInSeconds));
  104. }
  105. }, 1000);
  106. console.log("Better AGDQ Shedule done");
  107. })();
  108.  
  109. function timeFormatting(time)
  110. {
  111. //console.log("TimeFormatting:" + time);
  112. //console.log("Länge: " + time.length);
  113. //console.log(time);
  114. if(time.length == 7)
  115. {
  116. time = "0" + time;
  117. }
  118. else if(time.length == 10)
  119. {
  120. time = time.replace(/ /g, "0");
  121. }
  122. else
  123. {
  124. time = time;
  125. }
  126. return time;
  127. }
  128.  
  129. function secondsToTime(seconds)
  130. {
  131. var hours = Math.floor((seconds/60/60));
  132. seconds = seconds - hours*60*60;
  133. var minutes = Math.floor((seconds/60));
  134. seconds = seconds - minutes*60;
  135. return(addZero(hours) + ":" + addZero(minutes) + ":" + addZero(seconds));
  136. }
  137.  
  138. function addZero(time)
  139. {
  140. if(time.toString().length == 1)
  141. {
  142. return ("0" + time);
  143. }
  144. else return ("" + time);
  145. }