const rules = [ //Maanantai { day:1, from: 0, to: 9, url: 'https://www.buutti.fi/veikkola55lcd2/' }, { day:1, from: 9, to: 15, url: 'https://www.buutti.fi/veikkola_55lcd_1/' }, { day:1, from: 15, to: 23, url: 'https://www.buutti.fi/tavernadawi2/' }, //Tiistai { day:2, from: 0, to: 9, url: 'https://www.buutti.fi/veikkola55lcd2/' }, { day:2, from: 9, to: 15, url: 'https://www.buutti.fi/veikkola55lcd1/' }, { day:2, from: 15, to: 23, url: 'https://www.buutti.fi/veikkola55lcd2/' }, //Keskiviikko { day:3, from: 0, to: 9, url: 'https://www.buutti.fi/tavernadawi2/' }, { day:3, from: 9, to: 15, url: 'https://www.buutti.fi/tavernadawi1/' }, { day:3, from: 15, to: 23, url: 'https://www.buutti.fi/tavernadawi2/' }, //Torstai { day:4, from: 0, to: 9, url: 'https://www.buutti.fi/tavernadawi2/' }, { day:4, from: 9, to: 15, url: 'https://www.buutti.fi/tavernadawi1/' }, { day:4, from: 15, to: 23, url: 'https://www.buutti.fi/tavernadawi2/' }, //Perjantai { day:5, from: 0, to: 9, url: 'https://www.buutti.fi/tavernadawi2/' }, { day:5, from: 9, to: 15, url: 'https://www.buutti.fi/tavernadawi1/' }, { day:5, from: 15, to: 23, url: 'https://www.buutti.fi/tavernadawi2/' }, //Lauantai { day:6, from: 0, to: 9, url: 'https://www.buutti.fi/tavernadawi2/' }, { day:6, from: 9, to: 15, url: 'https://www.buutti.fi/tavernadawi1/' }, { day:6, from: 15, to: 23, url: 'https://www.buutti.fi/tavernadawi2/' }, //Sunnuntai { day:0, from: 0, to: 9, url: 'https://www.buutti.fi/tavernadawi2/' }, { day:0, from: 9, to: 15, url: 'https://www.buutti.fi/tavernadawi1/' }, { day:0, from: 15, to: 23, url: 'https://www.buutti.fi/tavernadawi2/' }, ]; const yo = 'https://www.buutti.fi/veikkola55lcd2'; window.onload = function() { redirect() }; function getRedirectUrl() { const now = new Date(); const today = now.getDay(); var hours = now.getHours(); hours = parseInt(hours); console.log('ny tunnit :: ', hours); if(hours == 23){ return yo; } else{ for(var i = 0; i< rules.length; i++){ if(rules[i].day == today){ if(hours >= rules[i].from ){ console.log(rules[i]); if(hours < rules[i].to){ console.log('kakkone',rules[i].url) return rules[i].url; } } } } } console.log(today); } function redirect() { var value = getRedirectUrl(); var thisUrl = window.location.href; if (value == thisUrl){ console.log('do nothing') return; } else if(value != ''){ console.log(value); window.location.href = value; } else { window.location.href = varmuusUrl; } } function tick() { //get the mins of the current time var mins = new Date().getMinutes(); if ((mins == "30") || (mins == "15") || (mins == "00") || (mins == "45") || (mins == "04") || (mins == "52") || (mins == "48")) { console.log('OSUMA') redirect(); } console.log('Tick ' + mins); } setInterval(tick, 60000);