| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | const ONE_KB = 1024; | 
					
						
							|  |  |  | const ONE_MB = ONE_KB * 1024; | 
					
						
							|  |  |  | const ONE_GB = ONE_MB * 1024; | 
					
						
							|  |  |  | const ONE_TB = ONE_GB * 1024; | 
					
						
							|  |  |  | const ONE_PB = ONE_TB * 1024; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function sizeFormat(size) { | 
					
						
							| 
									
										
										
										
											2023-05-24 23:41:09 +00:00
										 |  |  |     if (size < 0) { | 
					
						
							|  |  |  |         return "0 B"; | 
					
						
							|  |  |  |     } else if (size < ONE_KB) { | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |         return size.toFixed(0) + " B"; | 
					
						
							|  |  |  |     } else if (size < ONE_MB) { | 
					
						
							|  |  |  |         return (size / ONE_KB).toFixed(2) + " KB"; | 
					
						
							|  |  |  |     } else if (size < ONE_GB) { | 
					
						
							|  |  |  |         return (size / ONE_MB).toFixed(2) + " MB"; | 
					
						
							|  |  |  |     } else if (size < ONE_TB) { | 
					
						
							|  |  |  |         return (size / ONE_GB).toFixed(2) + " GB"; | 
					
						
							|  |  |  |     } else if (size < ONE_PB) { | 
					
						
							|  |  |  |         return (size / ONE_TB).toFixed(2) + " TB"; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return (size / ONE_PB).toFixed(2) + " PB"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 12:18:23 +00:00
										 |  |  | function cpuSpeedFormat(speed) { | 
					
						
							| 
									
										
										
										
											2023-05-25 12:43:54 +00:00
										 |  |  |     if (speed > 1000) { | 
					
						
							|  |  |  |         const GHz = speed / 1000; | 
					
						
							|  |  |  |         return GHz.toFixed(2) + " GHz"; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return speed.toFixed(2) + " MHz"; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-25 12:18:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function cpuCoreFormat(cores) { | 
					
						
							|  |  |  |     if (cores === 1) { | 
					
						
							|  |  |  |         return "1 Core"; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return cores + " Cores"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | function base64(str) { | 
					
						
							|  |  |  |     return Base64.encode(str); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function safeBase64(str) { | 
					
						
							|  |  |  |     return base64(str) | 
					
						
							|  |  |  |         .replace(/\+/g, '-') | 
					
						
							|  |  |  |         .replace(/=/g, '') | 
					
						
							|  |  |  |         .replace(/\//g, '_'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function formatSecond(second) { | 
					
						
							|  |  |  |     if (second < 60) { | 
					
						
							|  |  |  |         return second.toFixed(0) + ' s'; | 
					
						
							|  |  |  |     } else if (second < 3600) { | 
					
						
							|  |  |  |         return (second / 60).toFixed(0) + ' m'; | 
					
						
							|  |  |  |     } else if (second < 3600 * 24) { | 
					
						
							|  |  |  |         return (second / 3600).toFixed(0) + ' h'; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return (second / 3600 / 24).toFixed(0) + ' d'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function addZero(num) { | 
					
						
							|  |  |  |     if (num < 10) { | 
					
						
							|  |  |  |         return "0" + num; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return num; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function toFixed(num, n) { | 
					
						
							|  |  |  |     n = Math.pow(10, n); | 
					
						
							|  |  |  |     return Math.round(num * n) / n; | 
					
						
							| 
									
										
										
										
											2023-02-12 13:50:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  | function debounce(fn, delay) { | 
					
						
							|  |  |  |     var timeoutID = null; | 
					
						
							| 
									
										
										
										
											2023-02-12 13:50:09 +00:00
										 |  |  |     return function () { | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  |         clearTimeout(timeoutID); | 
					
						
							|  |  |  |         var args = arguments; | 
					
						
							|  |  |  |         var that = this; | 
					
						
							|  |  |  |         timeoutID = setTimeout(function () { | 
					
						
							|  |  |  |             fn.apply(that, args); | 
					
						
							|  |  |  |         }, delay); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getCookie(cname) { | 
					
						
							|  |  |  |     let name = cname + '='; | 
					
						
							| 
									
										
										
										
											2023-05-22 13:10:08 +00:00
										 |  |  |     let ca = document.cookie.split(';'); | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  |     for (let i = 0; i < ca.length; i++) { | 
					
						
							|  |  |  |         let c = ca[i]; | 
					
						
							|  |  |  |         while (c.charAt(0) == ' ') { | 
					
						
							|  |  |  |             c = c.substring(1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (c.indexOf(name) == 0) { | 
					
						
							| 
									
										
										
										
											2023-05-22 13:10:08 +00:00
										 |  |  |             // decode cookie value only
 | 
					
						
							|  |  |  |             return decodeURIComponent(c.substring(name.length, c.length)); | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-02-12 13:50:09 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  |     return ''; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-22 13:10:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  | function setCookie(cname, cvalue, exdays) { | 
					
						
							|  |  |  |     const d = new Date(); | 
					
						
							|  |  |  |     d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); | 
					
						
							|  |  |  |     let expires = 'expires=' + d.toUTCString(); | 
					
						
							| 
									
										
										
										
											2023-05-22 13:10:08 +00:00
										 |  |  |     // encode cookie value
 | 
					
						
							|  |  |  |     document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + ';path=/'; | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-05-16 20:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-16 22:31:56 +00:00
										 |  |  | function usageColor(data, threshold, total) { | 
					
						
							|  |  |  |     switch (true) { | 
					
						
							|  |  |  |         case data === null: | 
					
						
							|  |  |  |             return 'blue'; | 
					
						
							|  |  |  |         case total <= 0: | 
					
						
							|  |  |  |             return 'blue'; | 
					
						
							|  |  |  |         case data < total - threshold: | 
					
						
							|  |  |  |             return 'cyan'; | 
					
						
							|  |  |  |         case data < total: | 
					
						
							|  |  |  |             return 'orange'; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             return 'red'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-16 20:09:59 +00:00
										 |  |  | function doAllItemsExist(array1, array2) { | 
					
						
							|  |  |  |     for (let i = 0; i < array1.length; i++) { | 
					
						
							|  |  |  |         if (!array2.includes(array1[i])) { | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2023-05-16 22:31:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-05-30 21:04:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | function buildURL({ host, port, isTLS, base, path }) { | 
					
						
							|  |  |  |     if (!host || host.length === 0) host = window.location.hostname; | 
					
						
							|  |  |  |     if (!port || port.length === 0) port = window.location.port; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isTLS === undefined) isTLS = window.location.protocol === "https:"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const protocol = isTLS ? "https:" : "http:"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     port = String(port); | 
					
						
							|  |  |  |     if (port === "" || (isTLS && port === "443") || (!isTLS && port === "80")) { | 
					
						
							|  |  |  |         port = ""; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         port = `:${port}`; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return `${protocol}//${host}${port}${base}${path}`; | 
					
						
							|  |  |  | } |