Check if a new WordPress post is successfully published with jQuery

I have replace the answer I gave yesterday with this newly updated and tested version. I also added some code to test with that changes Publish to Update after 6 seconds. Please give it a shot.

<input type="submit" name="save" id="publish" class="button button-primary button-large preventDefault" value="Publish">
<script>
    var publishButton = document.getElementById('publish');
    var checkPublishStatus = setInterval(function() {
        var isPublished = publishButton.value;
        console.log(isPublished);
        if (isPublished === 'Update') {
            alert('A new post has been successfully published');
            clearInterval(checkPublishStatus); // Stop the interval
        }
    }, 500); // Check every 500 milliseconds

    window.onload = function() {
        setTimeout(function(){
            document.querySelector('#publish').value="Update";
        }, 5000);
    }
</script>

Here is the jQuery version:


<script>
    var publishButton = $('#publish');
    var checkPublishStatus = setInterval(function() {
        var isPublished = publishButton.val();
        console.log(isPublished);
        if (isPublished === 'Update') {
            alert('A new post has been successfully published - JQUERY');
            clearInterval(checkPublishStatus); // Stop the interval
        }
    }, 500); // Check every 500 milliseconds

    $(window).on('load', function() {
        setTimeout(function(){
            $('#publish').val('Update');
        }, 5000);
    });
</script>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)