let currentJob = 0; window.addEventListener('message', function(event) { if (event.data.type == "open") { $('html, body').css('display', 'flex'); config = event.data.config; Object.entries(config.Jobs).forEach(([jobKey, job]) => { var dynamicContent = `
`; $("#dynamicContentContainer").append(dynamicContent); }); showJob(currentJob); } }); $("#up").on("click", function (event) { const nextJob = (currentJob + 1) % config.Jobs.length; showJob(nextJob); }); $("#down").on("click", function (event) { const prevJob = (currentJob - 1 + config.Jobs.length) % config.Jobs.length; showJob(prevJob); }); const showJob = (jobIndex) => { $(`#job-${currentJob}`).css("display", "none"); currentJob = jobIndex; $(`#job-${currentJob}`).css("display", "block"); $("#down").html(` ${config.Jobs[(currentJob - 1 + config.Jobs.length) % config.Jobs.length].name} `); $("#up").html(` ${config.Jobs[(currentJob + 1) % config.Jobs.length].name} `); } const startJob = (jobIndex) => { $('html, body').css('display', 'none'); $.post(`https://${GetParentResourceName()}/startJob`, JSON.stringify({ rank: config.Jobs[jobIndex].rank, name: config.Jobs[jobIndex].name, })); } document.onkeyup = function (data) { if (data.which == 27) { $('html, body').css('display', 'none'); currentJob = 0; $("#dynamicContentContainer").empty(); $.post(`https://${GetParentResourceName()}/close`, JSON.stringify({})); } };