Spaces:
Sleeping
Sleeping
| // intervalBegin() | |
| function intervalBegin(){ | |
| console.log('cheeckingg') | |
| // minutes= min *60*1000 | |
| // intervalAPI= setInterval( function() { | |
| // const delay = ms => new Promise(res => setTimeout(res, ms)); | |
| ajax("/refreshDropbox") | |
| .then(function(data) { | |
| self.postMessage(data); // Code depending on result | |
| }) | |
| // },3600000) // 60*60*1000 | |
| } | |
| function ajax(url) { | |
| return new Promise(function(resolve, reject) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.onload = function() { | |
| resolve(this.responseText); | |
| }; | |
| xhr.onerror = reject; | |
| xhr.open('POST', url); | |
| xhr.send(); | |
| }); | |
| } | |
| this.now = new Date(); | |
| this.hours = this.now.getHours(); | |
| this.minutes = this.now.getMinutes(); | |
| var millisTill10 = new Date(this.now.getFullYear(), this.now.getMonth(), this.now.getDate(), 9, 0, 0, 0) - this.now; | |
| console.log(this.now) | |
| if (millisTill10 < 0) { | |
| millisTill10 += 43200000; // try every 12 hours | |
| } | |
| setTimeout(function(){intervalBegin()}, millisTill10); | |