Greasy Fork 还支持 简体中文。

Datadog RUM log highlighting

Optional userscript that adds highting to relevant RUM entries specified by https://greasyfork.org/en/scripts/475250-sentry-to-datadog-rum-and-log-buttons

  1. // ==UserScript==
  2. // @name Datadog RUM log highlighting
  3. // @description Optional userscript that adds highting to relevant RUM entries specified by https://greasyfork.org/en/scripts/475250-sentry-to-datadog-rum-and-log-buttons
  4. // @version 1
  5. // @grant none
  6. // @match https://app.datadoghq.com/rum/sessions*
  7. // @namespace happyviking
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. //https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists
  12. function waitForElm(selector) {
  13. return new Promise(resolve => {
  14. if (document.querySelector(selector)) {
  15. return resolve(document.querySelector(selector));
  16. }
  17.  
  18. const observer = new MutationObserver(mutations => {
  19. if (document.querySelector(selector)) {
  20. observer.disconnect();
  21. resolve(document.querySelector(selector));
  22. }
  23. });
  24.  
  25. observer.observe(document.body, {
  26. childList: true,
  27. subtree: true
  28. });
  29. });
  30. }
  31.  
  32. const main = async () => {
  33.  
  34. await waitForElm('.dt-event_date') //Just waiting till it loads
  35.  
  36. const url = new URL(window.location)
  37. const params = url.searchParams
  38.  
  39. const from = params.get("highlight_from")
  40. const to = params.get("highlight_to")
  41.  
  42. if (!from || !to) return
  43.  
  44. document.querySelectorAll('tbody.log-dt-event').forEach(tbody => {
  45. let timestampText = tbody.querySelector(".dt-event_date").textContent //Example: Sep 13 15:39:44.766
  46. timestampText = timestampText.split(".")[0]
  47. timestampText += ` ${(new Date()).getFullYear()} UTC`
  48. const millis = (new Date(Date.parse(timestampText))).getTime()
  49.  
  50. if (millis > from && millis < to) tbody.style.backgroundColor = "#FFE993"
  51.  
  52. })
  53. }
  54.  
  55. //There are probably cleaner ways to do this but I don't really care, this works and this
  56. //is supposed to be fast
  57. let currentPage = location.href;
  58. main()
  59. setInterval(() =>
  60. {
  61. if (currentPage != location.href){
  62. currentPage = location.href;
  63. main()
  64. }
  65. }, 500);