AWS Cloudwatch Timeago

Show timeago in AWS CloudWatch Last Event Time

  1. // ==UserScript==
  2. // @name AWS Cloudwatch Timeago
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Show timeago in AWS CloudWatch Last Event Time
  6. // @author himalay
  7. // @match https://*.console.aws.amazon.com/cloudwatch/home*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. var waitInterval = setInterval(function () {
  13. var tBody = document.querySelector("#gwt-debug-dataTable tbody");
  14. if (tBody) {
  15. clearInterval(waitInterval);
  16. var observer = new MutationObserver(function (mutations) {
  17. mutations.forEach(function (mutation) {
  18. if (!mutation.addedNodes) return;
  19.  
  20. mutation.addedNodes.forEach(function (node) {
  21. var el = node.querySelector(".GIYU-ANBMNB > div");
  22. if (el) {
  23. var dateText = el.textContent.trim();
  24. if (dateText) {
  25. var timeAgo = ago(new Date(dateText).getTime());
  26. el.innerHTML += ` (${timeAgo})`;
  27. }
  28. }
  29. });
  30. });
  31. });
  32.  
  33. observer.observe(tBody, {
  34. childList: true,
  35. subtree: false,
  36. attributes: false,
  37. characterData: false,
  38. });
  39. }
  40. }, 100);
  41.  
  42. function ago(v){v=0|(Date.now()-v)/1e3;var a,b={second:60,minute:60,hour:24,day:7,week:4.35,month:12,year:1e4},c;for(a in b){c=v%b[a];if(!(v=0|v/b[a]))return c+' '+(c-1?a+'s':a)}}
  43. })();