Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

remaining time #79

Open
panaC opened this issue Apr 4, 2022 · 1 comment
Open

remaining time #79

panaC opened this issue Apr 4, 2022 · 1 comment

Comments

@panaC
Copy link
Member

panaC commented Apr 4, 2022


  const url = conv.user.params?.player?.current?.url;
  ok(url, 'error.urlNotValid')
  ok(isValidHttpUrl(url), 'error.urlNotValid');

  const webpub = await conv.di.opds.webpubRequest(url);
  ok(webpub, 'error.webpubNotDefined');

  const index = conv.user.params.player.current.index || 0;
  const time = conv.user.params.player.current.time || 0;

  let minutes = 0;
  if (Array.isArray(webpub.readingOrders)) {
    let remainingTime = 0;
    for (let i = index + 1; i < webpub.readingOrders.length; i += 1) {
      remainingTime += webpub.readingOrders[i].duration || 0;
    }
    const pos = (v) => (v < 0 ? 0 : v);
    remainingTime += pos((webpub.readingOrders[index].duration || 0) - time);

    if (remainingTime >= 60) {
      minutes = Math.floor(remainingTime / 60);
    }
  }

  const hours = Math.floor(minutes / 60);
  if (hours) {
    minutes = minutes % 60;
    conv.add('player.remaining.hoursAndMinute', { hours, minutes });
  } else {
    conv.add('player.remaining.minute', { minutes });
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant