GDQ Schedule Enhancements

22nd-century schedule technology

当前为 2019-01-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GDQ Schedule Enhancements
  3. // @namespace https://github.com/willmtemple/
  4. // @version 0.1
  5. // @description 22nd-century schedule technology
  6. // @author Will Temple
  7. // @match https://gamesdonequick.com/schedule
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. const _MONTHS = [
  12. "January",
  13. "February",
  14. "March",
  15. "April",
  16. "May",
  17. "June",
  18. "July",
  19. "August",
  20. "September",
  21. "October",
  22. "November",
  23. "December"
  24. ];
  25.  
  26. function _hasClass(e, v) {
  27. for (var i = 0; i < e.classList.length; i++) {
  28. if (e.classList[i] === v) {
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34.  
  35. function _dayAndMonthNumber(s) {
  36. const split = s.split(' ');
  37. const d_i = parseInt(split[1]);
  38. for (var i = 0; i < _MONTHS.length; i++) {
  39. if (split[0] === _MONTHS[i]) {
  40. return [i, d_i];
  41. }
  42. }
  43. return [undefined, d_i];
  44. }
  45.  
  46. function _hourMinute(s) {
  47. const time = s.split(' ');
  48. const hour_minute = time[0].split(':');
  49. const hInt = parseInt(hour_minute[0]);
  50. const mInt = parseInt(hour_minute[1]);
  51. var realHour = undefined;
  52. if (time[1] === "PM") {
  53. realHour = hInt === 12 ? 12 : hInt + 12;
  54. } else {
  55. realHour = hInt === 12 ? 0 : hInt;
  56. }
  57. return [realHour, mInt];
  58. }
  59.  
  60.  
  61. function _doHighlight() {
  62. const jQuery = window.$;
  63. var now = new Date();
  64.  
  65. const cells = jQuery('table#runTable tbody tr');
  66.  
  67. const year = now.getFullYear();
  68. var day = undefined;
  69. var month = undefined;
  70.  
  71. var prevPCell = undefined;
  72. var prevECell = undefined;
  73.  
  74. var clear = false;
  75. cells.each(function(i, tr) {
  76. if (clear) { return; }
  77.  
  78. if (_hasClass(tr, 'day-split')) {
  79. const ss = tr.children[0].innerText.split(',')[1].trim();
  80. const day_month = _dayAndMonthNumber(ss);
  81. day = day_month[1];
  82. month = day_month[0];
  83. } else if (!_hasClass(tr, 'second-row')) {
  84. const time = tr.children[0].innerText;
  85. const hour_minute = _hourMinute(time);
  86. const hour = hour_minute[0];
  87. const minute = hour_minute[1];
  88. const cellTime = new Date(year, month, day, hour, minute);
  89. if ( cellTime > now) {
  90. clear = true;
  91. prevPCell.id = 'current-run';
  92. prevPCell.style['background-color'] = '#fffedd';
  93. prevECell.style['background-color'] = '#fffedd';
  94. window.location.hash = '#current-run';
  95.  
  96. setTimeout(function() {
  97. prevPCell.id = "";
  98. prevPCell.style['background-color'] = "";
  99. prevECell.style['background-color'] = "";
  100. _doHighlight();
  101. }, cellTime.getTime() - now.getTime());
  102. } else {
  103. prevPCell = tr;
  104. }
  105. } else {
  106. prevECell = tr;
  107. }
  108. })
  109. }
  110.  
  111. (function() {
  112. 'use strict';
  113. _doHighlight();
  114. })();