<commit_before>window.addEventListener('message', async function (event) {
    if (event.origin !== '*') {
        // return;
    }
    let data = null;
    try {
        data = JSON.parse(event.data);
    } catch (err) {
        console.error(err);
    }

    function respond(error, result) {
        event.source.postMessage(JSON.stringify({
            uid: data.uid,
            error: error,
            result: result
        }), '*');
    }

    if (data.action === 'getUser') {
        try {
            const res = await fetch(
                'https://admin.egg/blog/ghost/api/canary/admin/users/me/'
            );
            const json = await res.json();
            respond(null, json);
        } catch (err) {
            respond(err, null);
        }
    }

    if (data.action === 'hideComment') {
        try {
            const res = await fetch('https://admin.egg/blog/ghost/api/canary/admin/comments/' + data.id + '/', {
                method: 'PUT',
                body: JSON.stringify({
                    comments: [{
                        id: data.id,
                        status: 'hidden'
                    }]
                }),
                headers: {
                    'Content-Type': 'application/json'
                }
            });
            const json = await res.json();
            respond(null, json);
        } catch (err) {
            respond(err, null);
        }
    }

    if (data.action === 'showComment') {
        try {
            const res = await fetch('https://admin.egg/blog/ghost/api/canary/admin/comments/' + data.id + '/', {
                method: 'PUT',
                body: JSON.stringify({
                    comments: [{
                        id: data.id,
                        status: 'published'
                    }]
                }),
                headers: {
                    'Content-Type': 'application/json'
                }
            });
            const json = await res.json();<commit_msg>Updated message handler for dynamic admin urls<commit_after>const adminUrl = window.location.href.replace('auth-frame/', '');

window.addEventListener('message', async function (event) {
    if (event.origin !== '*') {
        // return;
    }
    let data = null;
    try {
        data = JSON.parse(event.data);
    } catch (err) {
        console.error(err);
    }

    function respond(error, result) {
        event.source.postMessage(JSON.stringify({
            uid: data.uid,
            error: error,
            result: result
        }), '*');
    }

    if (data.action === 'getUser') {
        try {
            const res = await fetch(
                adminUrl + 'api/canary/admin/users/me/'
            );
            const json = await res.json();
            respond(null, json);
        } catch (err) {
            respond(err, null);
        }
    }

    if (data.action === 'hideComment') {
        try {
            const res = await fetch(adminUrl + 'api/canary/admin/comments/' + data.id + '/', {
                method: 'PUT',
                body: JSON.stringify({
                    comments: [{
                        id: data.id,
                        status: 'hidden'
                    }]
                }),
                headers: {
                    'Content-Type': 'application/json'
                }
            });
            const json = await res.json();
            respond(null, json);
        } catch (err) {
            respond(err, null);
        }
    }

    if (data.action === 'showComment') {
        try {
            const res = await fetch(adminUrl + 'api/canary/admin/comments/' + data.id + '/', {
                method: 'PUT',
                body: JSON.stringify({
                    comments: [{
                        id: data.id,
                        status: 'published'
                    }]
                }),
                headers: {
                    'Content-Type': 'application/json'
                }
            });
            const json = await res.json();
{'fraction_non_alphanumeric': 0.1350816427511133, 'fraction_numerical': 0.0, 'mean_word_length': 1.107924921793535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6711985', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1022, 'n_words': 213}