mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-30 13:22:28 +03:00
1 line
5.0 KiB
JavaScript
1 line
5.0 KiB
JavaScript
function Q(n){return document.getElementById(n)}function QS(n){try{return Q(n).style}catch(n){}}function QE(n,t){try{Q(n).disabled=!t}catch(n){}}function QV(n,t){try{QS(n).display=t?"":"none"}catch(n){}}function QA(n,t){Q(n).innerHTML+=t}function QH(n,t){Q(n).innerHTML=t}function QC(n){try{return Q(n).classList}catch(n){}}function inputBoxFocus(n){Q(n).focus();var t=Q(n).value;Q(n).value="",Q(n).value=t}function ReadShort(n,t){return(n.charCodeAt(t)<<8)+n.charCodeAt(t+1)}function ReadShortX(n,t){return(n.charCodeAt(t+1)<<8)+n.charCodeAt(t)}function ReadInt(n,t){return 16777216*n.charCodeAt(t)+(n.charCodeAt(t+1)<<16)+(n.charCodeAt(t+2)<<8)+n.charCodeAt(t+3)}function ReadSInt(n,t){return(n.charCodeAt(t)<<24)+(n.charCodeAt(t+1)<<16)+(n.charCodeAt(t+2)<<8)+n.charCodeAt(t+3)}function ReadIntX(n,t){return 16777216*n.charCodeAt(t+3)+(n.charCodeAt(t+2)<<16)+(n.charCodeAt(t+1)<<8)+n.charCodeAt(t)}function ShortToStr(n){return String.fromCharCode(n>>8&255,255&n)}function ShortToStrX(n){return String.fromCharCode(255&n,n>>8&255)}function IntToStr(n){return String.fromCharCode(n>>24&255,n>>16&255,n>>8&255,255&n)}function IntToStrX(n){return String.fromCharCode(255&n,n>>8&255,n>>16&255,n>>24&255)}function MakeToArray(n){return n&&null!=n&&"object"!=typeof n?[n]:n}function SplitArray(n){return n.split(",")}function Clone(n){return JSON.parse(JSON.stringify(n))}function EscapeHtml(n){return"string"==typeof n?n.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<").replace(/"/g,""").replace(/'/g,"'"):"boolean"==typeof n||"number"==typeof n?n:void 0}function EscapeHtmlBreaks(n){return"string"==typeof n?n.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<").replace(/"/g,""").replace(/'/g,"'").replace(/\r/g,"<br />").replace(/\n/g,"").replace(/\t/g," "):"boolean"==typeof n||"number"==typeof n?n:void 0}function ArrayElementMove(n,t,e){n.splice(e,0,n.splice(t,1)[0])}function ObjectToStringEx(n,t){var e="";if(0!=n&&(!n||null==n))return"(Null)";if(n instanceof Array)for(var r in n)e+="<br />"+gap(t)+"Item #"+r+": "+ObjectToStringEx(n[r],t+1);else if(n instanceof Object)for(var r in n)e+="<br />"+gap(t)+r+" = "+ObjectToStringEx(n[r],t+1);else e+=EscapeHtml(n);return e}function ObjectToStringEx2(n,t){var e="";if(0!=n&&(!n||null==n))return"(Null)";if(n instanceof Array)for(var r in n)e+="\r\n"+gap2(t)+"Item #"+r+": "+ObjectToStringEx2(n[r],t+1);else if(n instanceof Object)for(var r in n)e+="\r\n"+gap2(t)+r+" = "+ObjectToStringEx2(n[r],t+1);else e+=EscapeHtml(n);return e}function gap(n){for(var t="",e=0;e<4*n;e++)t+=" ";return t}function gap2(n){for(var t="",e=0;e<4*n;e++)t+=" ";return t}function ObjectToString(n){return ObjectToStringEx(n,0)}function ObjectToString2(n){return ObjectToStringEx2(n,0)}function hex2rstr(n){if("string"!=typeof n||0==n.length)return"";for(var t,e="",r=(""+n).match(/../g);t=r.shift();)e+=String.fromCharCode("0x"+t);return e}function char2hex(n){return(n+256).toString(16).substr(-2).toUpperCase()}function rstr2hex(n){for(var t="",e=0;e<n.length;e++)t+=char2hex(n.charCodeAt(e));return t}function encode_utf8(n){return unescape(encodeURIComponent(n))}function decode_utf8(n){return decodeURIComponent(escape(n))}function data2blob(n){for(var t=new Array(n.length),e=0;e<n.length;e++)t[e]=n.charCodeAt(e);return new Blob([new Uint8Array(t)])}function utf2blob(n){for(var t=[],e=unescape(encodeURIComponent(n)),r=0;r<e.length;r++)t.push(e.charCodeAt(r));return new Blob([new Uint8Array(t)])}function random(n){return Math.floor(Math.random()*n)}function trademarks(n){return n.replace(/\(R\)/g,"®").replace(/\(TM\)/g,"™")}function zeroPad(n,t){null==t&&(t=2);n="00000000"+n;return n.substr(n.length-t)}function isAlphaNumeric(n){return"number"==typeof n||null!=n.match(/^[A-Za-z0-9]+$/)}function isSafeString(n){return"string"==typeof n&&-1==n.indexOf("<")&&-1==n.indexOf(">")&&-1==n.indexOf("&")&&-1==n.indexOf('"')&&-1==n.indexOf("'")&&-1==n.indexOf("+")&&-1==n.indexOf("(")&&-1==n.indexOf(")")&&-1==n.indexOf("#")&&-1==n.indexOf("%")&&-1==n.indexOf(":")}function isSafeString2(n){return"string"==typeof n&&-1==n.indexOf("<")&&-1==n.indexOf(">")&&-1==n.indexOf("&")&&-1==n.indexOf('"')&&-1==n.indexOf("'")&&-1==n.indexOf("+")&&-1==n.indexOf("(")&&-1==n.indexOf(")")&&-1==n.indexOf("#")&&-1==n.indexOf("%")}function parseUriArgs(n){var t,e=window.document.location.href,r={},o=(e=e.endsWith("#")?e.substring(0,e.length-1):e).split(/[\?&|]/);for(t in o.splice(0,1),o){var i,a=o[t],c=a.indexOf("=");r[i=a.substring(0,c)]=a.substring(c+1),n&&(r[i]=decodeURIComponent(a.substring(c+1))),isSafeString(r[i])?(c=parseInt(r[i]))==r[i]&&(r[i]=c):delete r[i]}return r}function check_webp_feature(t,e){var r=new Image;r.onload=function(){var n=0<r.width&&0<r.height;e(t,n)},r.onerror=function(){e(t,!1)},r.src="data:image/webp;base64,"+{lossy:"UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA"}[t]}String.prototype.startsWith||(String.prototype.startsWith=function(n){return 0===this.lastIndexOf(n,0)}),String.prototype.endsWith||(String.prototype.endsWith=function(n){return-1!==this.indexOf(n,this.length-n.length)}) |