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

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name     Datadog Log log highlighting
// @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
// @version  1
// @grant    none
// @match    https://app.datadoghq.com/logs*
// @namespace happyviking
// @license   MIT
// ==/UserScript==

//https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists
function waitForElm(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                observer.disconnect();
                resolve(document.querySelector(selector));
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
            attributes:true
        });
    });
}

const main = async () => {

    await waitForElm(".druids_typography_text.druids_typography_text--is-monospace.druids_time_formatted-time") //Just waiting till it loads

    const url = new URL(window.location)
    const params = url.searchParams

    const from = params.get("highlight_from")
    const to = params.get("highlight_to")

    if (!from || !to) return

    document.querySelectorAll(".druids_typography_text.druids_typography_text--is-monospace.druids_time_formatted-time").forEach(row => {
        let timestampText = row.textContent //Example: Sep 13 15:39:44.766
        timestampText = timestampText.split(".")[0]
        timestampText += ` ${(new Date()).getFullYear()} UTC`
        const millis = (new Date(Date.parse(timestampText))).getTime()
        
        if (millis > from && millis < to) row.style.backgroundColor = "#FFE993"

    })
}

//There are probably cleaner ways to do this but I don't really care, this works and this
//is supposed to be fast
let currentPage = location.href;
main()
setInterval(() =>
{
    if (currentPage != location.href){
        currentPage = location.href;
        main()
    }
}, 500);