AppVeyor Console Timestamp

Displays line timestamps in the job console

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

  1. // ==UserScript==
  2. // @name AppVeyor Console Timestamp
  3. // @version 0.5
  4. // @description Displays line timestamps in the job console
  5. // @license https://creativecommons.org/licenses/by-sa/4.0/
  6. // @namespace http://github.com/tony19
  7. // @match https://ci.appveyor.com/*/build/job/*
  8. // @grant GM_addStyle
  9. // @run-at document-idle
  10. // @author tony19@gmail.com
  11. // ==/UserScript==
  12. /* global GM_addStyle */
  13. /* jshint esnext:true, unused:true */
  14. (() => {
  15. 'use strict';
  16.  
  17. GM_addStyle(`
  18. div[title] a:first-child {
  19. width: 140px !important;
  20. background-color: black;
  21. }
  22. div[title] span:first-child {
  23. padding-left: 100px !important;
  24. }
  25. .job-console {
  26. background-color: black;
  27. }
  28. a.late {
  29. color: red;
  30. }
  31. `);
  32.  
  33. // number of seconds between timestamps that indicate excessive time spent
  34. const HIGH_WATERMARK = 3;
  35. let lastTime = '';
  36.  
  37. const timerId = setInterval(() => {
  38. const divs = $('div[title]:has(a):not([data-ts])');
  39. if (!divs || !divs.length) { return; }
  40.  
  41. divs.each((index, div) => {
  42. const timestamp = div.getAttribute('title');
  43. const anchor = $(div).find('a:first-child').append(` - ${timestamp}`);
  44. processLine(anchor, timestamp);
  45. });
  46. divs.attr('data-ts', '');
  47. }, 2000);
  48.  
  49. function processLine(anchor, timestamp) {
  50. const seconds = toSeconds(timestamp);
  51. if (seconds - lastTime >= HIGH_WATERMARK) {
  52. $(anchor).addClass('late');
  53. }
  54. lastTime = seconds;
  55. }
  56.  
  57. function toSeconds(hms) {
  58. const a = hms.split(':');
  59. const seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
  60. return seconds;
  61. }
  62. })();