1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

feat: mark media as read when playback reaches 90%

This commit is contained in:
Loïc Doubinine 2024-07-28 21:29:45 +02:00 committed by GitHub
parent 37309adbc0
commit 4f55361f5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 278 additions and 76 deletions

View file

@ -678,9 +678,13 @@ function goToAddSubscription() {
* save player position to allow to resume playback later
* @param {Element} playerElement
*/
function handlePlayerProgressionSave(playerElement) {
function handlePlayerProgressionSaveAndMarkAsReadOnCompletion(playerElement) {
if (!isPlayerPlaying(playerElement)) {
return; //If the player is not playing, we do not want to save the progression and mark as read on completion
}
const currentPositionInSeconds = Math.floor(playerElement.currentTime); // we do not need a precise value
const lastKnownPositionInSeconds = parseInt(playerElement.dataset.lastPosition, 10);
const markAsReadOnCompletion = parseFloat(playerElement.dataset.markReadOnCompletion); //completion percentage to mark as read
const recordInterval = 10;
// we limit the number of update to only one by interval. Otherwise, we would have multiple update per seconds
@ -691,9 +695,29 @@ function handlePlayerProgressionSave(playerElement) {
const request = new RequestBuilder(playerElement.dataset.saveUrl);
request.withBody({ progression: currentPositionInSeconds });
request.execute();
// Handle the mark as read on completion
if (markAsReadOnCompletion >= 0 && playerElement.duration > 0) {
const completion = currentPositionInSeconds / playerElement.duration;
if (completion >= markAsReadOnCompletion) {
handleEntryStatus("none", document.querySelector(":is(a, button)[data-toggle-status]"), true);
}
}
}
}
/**
* Check if the player is actually playing a media
* @param element the player element itself
* @returns {boolean}
*/
function isPlayerPlaying(element) {
return element &&
element.currentTime > 0 &&
!element.paused &&
!element.ended &&
element.readyState > 2; //https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/readyState
}
/**
* handle new share entires and already shared entries
*/