var loadScriptAsync = function(uri) {
return new Promise((resolve, reject) => {
var tag = document.createElement('script');
tag.src = uri;
tag.async = true;
tag.onload = () => {
resolve();
};
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
});
}
var scriptLoaded = loadScriptAsync('external-script.js');
scriptLoaded.then(function(){
//код для выполнения после загрузки внешнего скрипта
});
<div id='my_timer'>1:0:2</div>
<script>
function showTimeLess ()
{
function addZero (x) {return ((x < 10)? '0' : '') + x}
var t = Math.round (.001 * (sessionStorage.getItem ('timeset') - performance.now ()));
console.log(t);
document.getElementById ('my_timer').textContent = [addZero(Math.floor (t / 3600)), addZero(Math.floor ((t / 60) % 60)), addZero (t % 60)].join (':');
if (t) setTimeout (showTimeLess, 345);
}
var t = document.getElementById ('my_timer').textContent.split (':');
sessionStorage.setItem ('timeset', (t [0] * 3600 + t [1] * 60 + +t [2]) * 1000);
showTimeLess ();
</script>
const steps = Object.entries(answers).reduce((acc, [ key, val ]) => {
const question = questions.find(n => n.key === key);
const step = acc[val.step] = acc[val.step] || [];
step.push({
step: val.step,
question: { ...question.question },
answer: question.answer.values instanceof Object
? question.answer.values[val.answer].en
: val.answer,
});
return acc;
}, {});