Greasy Fork

Coursera - Estimated Time

Estimate the rest time of each course on its Coursera Welcome page to do a better Scrum

当前为 2017-12-27 提交的版本,查看 最新版本

// ==UserScript==
// @name         Coursera - Estimated Time
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Estimate the rest time of each course on its Coursera Welcome page to do a better Scrum
// @author       Artwalk
// @source       https://gist.github.com/Artwalk/18b594172c7b0b71f2bb210788b3939a
// @include      https://www.coursera.org/learn/*/home/welcome
// @match        https://www.coursera.org/learn/*/home/welcome
// @grant        none
// ==/UserScript==

(function() {
    setTimeout(function () {
        main()
    }, 1000);
})();

function main() {
     'use strict';

    let et = document.getElementsByClassName('body-2-text estimated-time')

    var h = 0, m = 0
    for (var i=0; i<et.length; i++) {
        let hm = et[i].outerText.split(" ").concat([0, 0, 0, 0])
        h += parseInt(hm[2])
        m += parseInt(hm[3])
    }
    h += m/60
    m %= 60

	var tmp = document.getElementsByClassName('items align-self-stretch')

	var div = document.createElement('div')
	div.className = 'rc-DefaultNavigationItem'

	var a = document.createElement('a')
	a.className = 'rc-NavigationLink horizontal-box align-items-vertical-center wrap'

	let hm = document.createElement('p')
	hm.textContent = 'Estimated Time: ' + h.toFixed(0) + 'h ' + m + 'm'
	hm.className = 'nav-item headline-1-text'


	div.appendChild(a)
	a.appendChild(hm)
	tmp[tmp.length-1].appendChild(div)
}