xxxxxxxxxx
<input type="text" name="" id="test">
<script>
setInterval(() => {
if(document.activeElement == document.getElementById('test')){
document.body.style.backgroundColor = 'red'
}else {
document.body.style.backgroundColor = 'lime'
}
}, 500);
</script>