forked from ChinaGodMan/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.js
More file actions
41 lines (41 loc) · 1.34 KB
/
Copy pathhelp.js
File metadata and controls
41 lines (41 loc) · 1.34 KB
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
41
export function getHumanReadableSize(sizeInKB) {
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
const size = sizeInKB * 1024
let i = parseInt(Math.floor(Math.log(size) / Math.log(1024)))
const humanReadableSize = (size / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]
return humanReadableSize
}
export function systemTime(isoString) {
const date = new Date(isoString)
return date.toLocaleString()
}
export function timeToSeconds(timeStr) {
let hours = 0, minutes = 0, seconds = 0
const hoursMatch = timeStr.match(/(\d+)h/)
const minutesMatch = timeStr.match(/(\d+)m/)
const secondsMatch = timeStr.match(/(\d+)s/)
if (hoursMatch) {
hours = parseInt(hoursMatch[1], 10)
}
if (minutesMatch) {
minutes = parseInt(minutesMatch[1], 10)
}
if (secondsMatch) {
seconds = parseInt(secondsMatch[1], 10)
}
let totalSeconds = (hours * 3600) + (minutes * 60) + seconds
return totalSeconds
}
export function isMobileDevice() {
return /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
}
export function extractPath(input) {
const thirdSlashIndex = input.indexOf(
'/',
input.indexOf('/', input.indexOf('/') + 1) + 1
)
if (thirdSlashIndex !== -1) {
return input.substring(0, thirdSlashIndex)
}
return input
}