Wes Bos Courses Duration

Prints course duration on console

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Wes Bos Courses Duration
// @namespace    https://github.com/xaxim/
// @version      0.4
// @description  Prints course duration on console
// @author       xaxim
// @match        https://javascript30.com/account/access/*
// @match        https://es6.io/account/access/*
// @match        https://reactforbeginners.com/account/access/*
// @match        https://sublimetextbook.com/account/access/*
// @match        https://flexbox.io/account/access/*
// @match        https://commandlinepoweruser.com/account/access/*
// @match        https://learnredux.com/account/access/*
// @match        https://masteringmarkdown.com/account/access/*
// @match        https://*/account/access/*
// @grant        none
// ==/UserScript==

function getWesDuration(start = 0, end) {
  const timeNodes = Array.from(document.querySelectorAll('.duration'));
  const last = end || timeNodes.length;

  const seconds = timeNodes
    .filter((node) => {
      const videoNumber = parseFloat(node.parentNode.parentNode.parentNode.querySelector('.video-number').textContent);
      return videoNumber >= start && videoNumber <= last;
    })
    .map(node => node.textContent)
    .map((timeStr) => {
      const [mins, secs] = timeStr.split(':').map(parseFloat);
      return (mins * 60) + secs;
    })
    .reduce((total, current) => total + current);

  const minsPerHour = 60;
  const secsPerHour = minsPerHour * 60;

  let secondsLeft = seconds;

  const hours = Math.floor(secondsLeft / secsPerHour);
  secondsLeft %= secsPerHour;

  const minutes = Math.floor(secondsLeft / minsPerHour);
  secondsLeft %= minsPerHour;

  /* eslint-disable */
  console.log(`Duration of this course: ${hours} hours ${minutes} minutes and ${secondsLeft} seconds`);
  /* eslint-enable */
}

getWesDuration();