forked from jaruba/PowderWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.js
More file actions
56 lines (42 loc) · 1.7 KB
/
Copy pathmisc.js
File metadata and controls
56 lines (42 loc) · 1.7 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export const getParameterByName = (name, url) => {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
export const readableSize = (fileSizeInBytes) => {
if (!fileSizeInBytes) return '0.0 kB';
var i = -1;
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
}
export const humanReadableTime = (secs) => {
var numhours = Math.floor(((secs % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((secs % 31536000) % 86400) % 3600) / 60);
var numseconds = (((secs % 31536000) % 86400) % 3600) % 60;
return (numhours ? (numhours + 'h ') : '') + (numminutes ? (numminutes + 'm ') : '') + (numseconds ? (numseconds + 's') : '');
}
export const jackettLinkAnchor = () => {
var OSName = 'Unknown OS'
if (navigator.appVersion.indexOf('Win') != -1) OSName = 'Windows'
if (navigator.appVersion.indexOf('Mac') != -1) OSName = 'MacOS'
if (navigator.appVersion.indexOf('X11') != -1) OSName = 'UNIX'
if (navigator.appVersion.indexOf('Linux') != -1) OSName = 'Linux'
var linkAnchor = ''
if (['Unknown OS', 'Windows'].indexOf(OSName) > -1) {
linkAnchor = 'installation-on-windows'
} else if (['MacOS'].indexOf(OSName) > -1) {
linkAnchor = 'installation-on-macos'
} else if (['UNIX', 'Linux'].indexOf(OSName) > -1) {
linkAnchor = 'installation-on-linux'
}
return linkAnchor
}
export default {}