document.addEventListener('DOMContentLoaded', () => { const phperTokenElem = document.getElementsByClassName('js-phper-token')[0]; const aggregatedStatusElem = document.getElementsByClassName('js-aggregated-execution-status')[0]; const aggregatedStatusLoadingIndicatorElem = document.getElementsByClassName('js-aggregated-execution-status-loading-indicator')[0]; const answerId = aggregatedStatusElem.dataset.answerId; const getElemsMap = cls => new Map( Array.from(document.getElementsByClassName(cls) ?? []) .map(e => [parseInt(e.dataset.testcaseExecutionId), e]) ); const statusElemsMap = getElemsMap('js-testcase-execution-status'); const statusLoadingIndicatorElemsMap = getElemsMap('js-testcase-execution-status-loading-indicator'); const stdoutElemsMap = getElemsMap('js-testcase-execution-stdout'); const stderrElemsMap = getElemsMap('js-testcase-execution-stderr'); if (!aggregatedStatusLoadingIndicatorElem) { return; } const apiUrl = `${process.env.ALBATROSS_BASE_PATH}/api/answers/${answerId}/statuses`; let timerId; timerId = setInterval(() => { fetch(apiUrl) .then(response => response.json()) .then(({ aggregated_status, testcase_executions, phper_token }) => { if (phper_token) { phperTokenElem.innerHTML = `