var startRefresh = function() { window.worker = setTimeout(function() { location.reload(); }, 3000); } window.worker = null; $('#refreshButton').on('click', function() { if (window.localStorage.refresh == undefined) { window.localStorage.refresh = 'true' } else{ delete window.localStorage.refresh } console.log(window.localStorage.refresh) if (window.localStorage.refresh == 'true') { startRefresh() $('#refreshButton').html('AUTO RELOAD ON') $(this).addClass("btn-info") $(this).removeClass("btn-warning") } else { clearTimeout(window.worker) $('#refreshButton').html('AUTO RELOAD OFF') $(this).addClass("btn-warning") $(this).removeClass("btn-info") } }) if (window.localStorage.refresh == 'true') { $('#refreshButton').html('AUTO RELOAD ON') $('#refreshButton').addClass("btn-info") $('#refreshButton').removeClass("btn-warning") startRefresh() } $("#start_script").click(function(){ $.ajax({url: "/start", success: function(result){ }}); }); $("#stop_script").click(function(){ $.ajax({url: "/stop", success: function(result){ }}); });