-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdurationBrowser.js
40 lines (31 loc) · 1.21 KB
/
durationBrowser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// const regex_ytPlaylist = new RegExp(/^.*(youtu.com\/|list=)([^#\&\?]*).*/)
const nbVideos = Array.from(document.querySelectorAll('#index')).pop().innerText
//const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1
const times = Array
.from(document.querySelectorAll('.style-scope.ytd-thumbnail-overlay-time-status-renderer'))
.map(v => v.textContent)
.map(item => item.replace('↵', '').trim().split(':').map(Number))
.filter(t => t.length === 2 || t.length === 3)
.map(t => t.length === 2 ? [0].concat(t) : t)
const addTime = (acc, current, i) => {
const [hours, minutes, seconds] = current
console.log(`Video ${i + 1} => hours: ${hours} minutes: ${minutes} seconds: ${seconds}`)
acc.s += seconds
acc.m += minutes
acc.h += hours
return acc
}
const total = times.reduce(addTime, { d: 0, h: 0, m: 0, s: 0 })
console.log(total)
let { d, h, m, s } = total
let retainer = s - (s % 60)
s -= retainer
m += (retainer / 60)
retainer = m - (m % 60)
m -= retainer
h += (retainer / 60)
retainer = h - (h % 24)
h -= retainer
d = retainer / 24
console.log(`${d}day${d > 1 ? 's' : ''} ${h}h ${m}m ${s}s`)
alert(`${d}day${d > 1 ? 's' : ''} ${h}h ${m}m ${s}s`)