Greasy Fork 支持简体中文。

Datadog Log log highlighting

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

  1. // ==UserScript==
  2. // @name Datadog Log log highlighting
  3. // @description Optional userscript that adds highting to relevant Log 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/logs*
  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. attributes:true
  29. });
  30. });
  31. }
  32.  
  33. const main = async () => {
  34.  
  35. await waitForElm(".druids_typography_text.druids_typography_text--is-monospace.druids_time_formatted-time") //Just waiting till it loads
  36.  
  37. const url = new URL(window.location)
  38. const params = url.searchParams
  39.  
  40. const from = params.get("highlight_from")
  41. const to = params.get("highlight_to")
  42.  
  43. if (!from || !to) return
  44.  
  45. document.querySelectorAll(".druids_typography_text.druids_typography_text--is-monospace.druids_time_formatted-time").forEach(row => {
  46. let timestampText = row.textContent //Example: Sep 13 15:39:44.766
  47. timestampText = timestampText.split(".")[0]
  48. timestampText += ` ${(new Date()).getFullYear()} UTC`
  49. const millis = (new Date(Date.parse(timestampText))).getTime()
  50. if (millis > from && millis < to) row.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);