FAH Timeout Display (Chrome, Tampermonkey)

Display timeout and other WU related information

  1. // ==UserScript==
  2. // @name FAH Timeout Display (Chrome, Tampermonkey)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Display timeout and other WU related information
  6. // @author Rejutka Lupex
  7. // @match http://folding.stanford.edu/nacl/
  8. // @grant none
  9. // @run-at document-body
  10. // ==/UserScript==
  11.  
  12. var myConsole = null;
  13. const fahInfoBox = "_fahExtInfoBox";
  14. const fahTimeField = "_fahExtTimeField";
  15. var weekday = new Array(7);
  16. weekday[0]= "Sunday";
  17. weekday[1] = "Monday";
  18. weekday[2] = "Tuesday";
  19. weekday[3] = "Wednesday";
  20. weekday[4] = "Thursday";
  21. weekday[5] = "Friday";
  22. weekday[6] = "Saturday";
  23.  
  24. var month = new Array(12);
  25. month[0] = "January";
  26. month[1] = "February";
  27. month[2] = "March";
  28. month[3] = "April";
  29. month[4] = "May";
  30. month[5] = "June";
  31. month[6] = "July";
  32. month[7] = "August";
  33. month[8] = "September";
  34. month[9] = "October";
  35. month[10] = "November";
  36. month[11] = "December";
  37.  
  38. (function() {
  39. 'use strict';
  40.  
  41. //We take over console.log, which is used by FAH, so we can catch log entries of interest.
  42. if (myConsole === null)
  43. {
  44. //Easier to make a copy of the whole console object
  45. myConsole = window.console;
  46.  
  47. //Now replace the original log method with ours
  48. window.console.log = function()
  49. {
  50. //This is only supposesd to be called once, but we have to check it here
  51. //because at the time this script is called there is no body.onLoad yet
  52. if (document.getElementById("panel"))
  53. {
  54. if (document.getElementById(fahInfoBox) === null ||document.getElementById(fahInfoBox) === undefined )
  55. {
  56. var iField = document.createElement('div');
  57. iField.id = fahInfoBox;
  58. document.getElementById("panel").appendChild(iField);
  59.  
  60. var timeField = document.createElement("div");
  61. timeField.id = fahTimeField;
  62. document.getElementById(fahInfoBox).appendChild(timeField);
  63. }
  64. }
  65.  
  66. //Send the original data on its way, so the log doesn't get disturbed
  67. console.info.apply(myConsole, arguments);
  68.  
  69. var infoLine = arguments[0];
  70. //We only need the client id data block
  71. if (infoLine.indexOf('DEBUG: WU: {"client_id":"') != -1)
  72. {
  73. //As I understand it, this huge line is a JSon object/array:
  74. //Parsing probably takes time - but it ensures we get the right info
  75. var WUData = JSON.parse(infoLine.substr(10, infoLine.length));
  76. var wu_ts = new Date(WUData.wu_ts);
  77. var wu_dl = new Date(WUData.deadline);
  78. var wu_to = new Date(WUData.timeout);
  79.  
  80. var wu_maxtime = (wu_to - wu_ts) / 1000;
  81. var wu_maxmin = wu_maxtime / 60;
  82.  
  83. var wuTimeMessage = document.createElement("span");
  84. wuTimeMessage.innerHTML = "Start of WU: " + wu_ts.getHours() + ":" + wu_ts.getMinutes()+ " " + weekday[wu_ts.getDay()] + " " + month[wu_ts.getMonth()] + " " + wu_ts.getFullYear();
  85. wuTimeMessage.innerHTML += "<br />";
  86. wuTimeMessage.innerHTML += "Timeout: " + wu_to.getHours() + ":" + wu_to.getMinutes() + " " + weekday[wu_to.getDay()] + " " + month[wu_to.getMonth()] + " " + wu_to.getFullYear();
  87. wuTimeMessage.innerHTML += "<br />";
  88. wuTimeMessage.innerHTML += "Minutes from start to timeout:" + wu_maxmin;
  89.  
  90. var tmpTimeField = document.getElementById(fahTimeField);
  91. while (tmpTimeField.firstChild)
  92. tmpTimeField.removeChild(tmpTimeField.firstChild);
  93.  
  94. tmpTimeField.appendChild(wuTimeMessage);
  95. }
  96.  
  97. };
  98. }
  99. })();