Last active
October 17, 2017 18:22
-
-
Save boertel/57c4c309483699d6d341fdd45abbf0f4 to your computer and use it in GitHub Desktop.
France Inter à la bonne heure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Ecouter France Inter à la bonne heure | |
* https://www.franceinter.fr/programmes | |
* | |
*/ | |
var emissions = $('.rich-section-list-gdp-item:not(.step)').map(function () { | |
var date = new Date($(this).attr('data-start-time') * 1000); | |
var emission = { | |
hours: (date.getHours() + 9) % 24, | |
minutes: date.getMinutes(), | |
element: $(this), | |
}; | |
return emission; | |
}) | |
var audio = $('audio')[0]; | |
var now = { | |
hours: new Date().getHours(), | |
minutes: new Date().getMinutes(), | |
}; | |
for (var i = 0; i < emissions.length - 1; i += 1) { | |
var current = emissions[i]; | |
var next = emissions[i + 1]; | |
var nowMinutes = now.hours * 60 + now.minutes; | |
var currentMinutes = current.hours * 60 + current.minutes; | |
var nextMinutes = next.hours * 60 + next.minutes; | |
if (currentMinutes <= nowMinutes && nowMinutes < nextMinutes) { | |
var goToMinutes = nowMinutes - currentMinutes; | |
current.element.find('button')[0].click() | |
audio.muted = true; | |
audio.addEventListener('loadeddata', function() { | |
audio.pause(); | |
window.setTimeout(function() { | |
audio.muted = false; | |
audio.currentTime = goToMinutes * 60 | |
audio.play(); | |
}, 1000); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment