UNPKG

16.9 kBJavaScriptView Raw
1/*!
2 * Buession prototype v2.2.0
3 *
4 * @link https://prototype.buession.com/
5 * @source https://github.com/buession/buession-prototype
6 * @copyright @ 2020-2023 Buession.com Inc.
7 * @license MIT
8 * @Build Time Wed, 01 Feb 2023 06:44:53 GMT
9 */
10!function(){"use strict";window.Prototype={version:"v2.2.0",emptyFunction:function(){},K:function(e){return e}};var e={these:function(){for(var e,t=0;t<arguments.length;t++){var n=arguments[t];if(Object.isFunction(n))try{e=n();break}catch(e){console.error(e)}}return e}};window.Try=e;var t,n=function(){function e(e){this.value=e}return e.of=function(t){return new e(t)},e.ofNullable=function(t){return Object.isUndefinedOrNull(t)?e.empty():new e(t)},e.empty=function(){return new e(null)},e.prototype.get=function(){if(null===this.value||void 0===this.value)throw"No value present";return this.value},e.prototype.orElse=function(e){return Object.isUndefinedOrNull(this.value)?e:this.value},e.prototype.isPresent=function(){return!1===Object.isUndefinedOrNull(this.value)},e}();window.Optional=n,Object.type=function(e){return typeof e},Object.rawType=function(e){return Object.prototype.toString.call(e).slice(8,-1)},Object.isObject=function(e){return null!==e&&"object"==typeof e},Object.isPlainObject=function(e){return"[object Object]"===Object.prototype.toString.call(e)},Object.isMap=function(e){return"[object Map]"===Object.prototype.toString.call(e)},Object.isSet=function(e){return"[object Set]"===Object.prototype.toString.call(e)},Object.isFunction=function(e){return"function"===Object.type(e)},Object.isSymbol=function(e){if("symbol"==typeof e)return!0;try{var t=Symbol.prototype.toString;return"symbol"==typeof e.valueOf()&&/^Symbol\(.*\)$/.test(t.call(e))}catch(e){return!1}},Object.isPromise=function(e){return!1===Object.isUndefinedOrNull(e)&&Object.isFunction(e.then)&&Object.isFunction(e.catch)},Object.isPrimitive=function(e){return Object.isBoolean(e)||Object.isString(e)||Object.isNumber(e)},Object.isArray=function(e){return Array.isArray(e)},Object.isString=function(e){return"string"===Object.type(e)},Object.isNumber=function(e){return"number"===Object.type(e)},Object.isBoolean=function(e){return"boolean"===Object.type(e)},Object.isRegExp=function(e){return"RegExp"===Object.rawType(e)},Object.isFile=function(e){return e instanceof File},Object.isWindow=function(e){return Object.isUndefinedOrNull(e)&&e==e.window},Object.isElement=function(e){return!Object.isUndefinedOrNull(e)&&!(1!=e.nodeType)},Object.isEvent=function(e){return e instanceof Event},Object.isNull=function(e){return null===e},Object.isUndefined=function(e){return void 0===e},Object.isUndefinedOrNull=function(e){return Object.isUndefined(e)||Object.isNull(e)},Object.clone=function(e){if(Object.isString(e))return String(e);if(Object.isArray(e))return Array.prototype.slice.apply(e);if(Object.isPlainObject(e)){var t={};return Object.keys(e).forEach((function(n){t[n]=Object.clone(e[n])})),t}return e},Object.equals=function(e,t){if(e===t)return!0;if(!(e instanceof Object&&t instanceof Object))return!1;if(e.constructor!==t.constructor)return!1;if(Object.isArray(e)&&Object.isArray(t)&&e.length===t.length){for(var n=0;n<e.length;n++)if(!1===Object.equals(e[n],t[n]))return!1}else{if(!Object.isObject(e)||!Object.isObject(t)||Object.keys(e).length!==Object.keys(t).length)return!1;for(var r in e)if(e.hasOwnProperty.call(r)&&!1===Object.equals(e[r],t[r]))return!1}return!0},Object.omit=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=Object.assign({},e),i=0;i<t.length;i++){var o=t[i];delete r[o]}return r},Array.prototype.isEmpty=function(){return 0===this.length},Array.prototype.exists=function(e){return-1!==this.indexOf(e)},Array.prototype.first=function(){if(0===this.length)throw"Array index out of range: 0";return this[0]},Array.prototype.last=function(){if(0===this.length)throw"Array index out of range: 0";return this[this.length-1]},Array.prototype.each=Array.prototype.forEach,Array.prototype.size=function(){return this.length},Array.prototype.merge=Array.prototype.concat,Array.prototype.compact=function(){return this.filter((function(e){return Object.isUndefinedOrNull(e)}))},Array.prototype.unique=function(){var e=new Array;return this.filter((function(t){var n=!1===e.includes(t);return e.push(t),n}))},Array.prototype.without=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this.filter((function(t){return!1===e.includes(t)}))},Array.prototype.clone=function(){return this.slice(0)},Array.prototype.clear=function(){return this.length=0,this},Date.prototype.isLeapYear=function(){var e=this.getFullYear();return e%4==0&&(e%100!=0||e%400==0)},Date.prototype.getSeason=function(){var e=this.getMonth();return e>=3&&e<=5?0:e>=6&&e<=8?1:e>=9&&e<=11?2:e>=12||e<=2?3:0},Date.prototype.getDayOfYear=function(){for(var e=1==this.isLeapYear()?[31,29,31,30,31,30,31,31,30,31,30,31]:[31,28,31,30,31,30,31,31,30,31,30,31],t=this.getDate(),n=0;n<this.getMonth();n++)t+=e[n];return t},Date.prototype.getDaysOfYear=function(){return this.isLeapYear()?366:365},Date.prototype.format=function(e){if(!1===Object.isString(e))throw"Invalid argument format";var t=this,n={N:["Spring","Summer","Autumn","Winter"],A:["春","夏","秋","冬"]},r={f:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],F:["January","February","March","April","May","June","July","August","September","October","November","December"],C:["一","二","三","四","五","六","七","八","九","十","十一","十二"]},i={W:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],WW:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],WC:["日","一","二","三","四","五","六"]},o=function(){return Math.floor((t.getMonth()+3)/3)},u={y:function(e){return console.debug("y => pattern: "+e),(t.getFullYear()+"").substring(4-e.length)},n:function(e){return console.debug("n => pattern: "+e),o()},N:function(e){console.debug("N => pattern: "+e);var t=o()-1;return n.N[t]},A:function(e){console.debug("A => pattern: "+e);var t=o()-1;return n.A[t]},M:function(e){console.debug("M => pattern: "+e);var n=t.getMonth()+1;return(n<10?"0"+n:""+n).substring(2-e.length)},f:function(e){console.debug("f => pattern: "+e);var n=t.getMonth();return r.f[n]},F:function(e){console.debug("F => pattern: "+e);var n=t.getMonth();return r.F[n]},C:function(e){console.debug("C => pattern: "+e);var n=t.getMonth();return r.C[n]},e:function(e){return console.debug("e => pattern: "+e),t.getDay()},E:function(e){return console.debug("E => pattern: "+e),t.getDay()+1},l:function(e){console.debug("l => pattern: "+e);var n=t.getDay();return i.W[n]},L:function(e){console.debug("L => pattern: "+e);var n=t.getDay();return i.WC[n]},w:function(e){console.debug("w => pattern: "+e);var n=t.getDay();return i.WC[n]},d:function(e){console.debug("d => pattern: "+e);var n=t.getDate();return(n<10?"0"+n:""+n).substring(2-e.length)},h:function(e){console.debug("h => pattern: "+e);var n=t.getHours();return(n<10?"0"+n:""+n).substring(2-e.length)},H:function(e){console.debug("H => pattern: "+e);var n=t.getHours();return(n<10?"0"+n:""+n).substring(2-e.length)},m:function(e){console.debug("m => pattern: "+e);var n=t.getMinutes();return(n<10?"0"+n:""+n).substring(2-e.length)},s:function(e){console.debug("s => pattern: "+e);var n=t.getSeconds();return(n<10?"0"+n:""+n).substring(2-e.length)},S:function(e){console.debug("S => pattern: "+e);var n=t.getMilliseconds();return(n<10?"0"+n:""+n).substring(2-e.length)}};return e.replace(/([ynNAMfFCdYTjeElLwWiohHmsSaOPZ])+/g,(function(e,t){var n=u[t];return!0===Object.isFunction(n)?n(e):e}))},function(e){e.NONE="None",e.LAX="Lax",e.STRICT="Strict"}(t||(t={}));var r=function(){function e(){}return e.prototype.set=function(e,t,n){var r=e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent),i=t?encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent):"",o="";if(n){if(o+=n.domain?"; domain="+n.domain:"",o+=n.path?"; path="+n.path:"",n.expires){var u=n.expires instanceof Date?n.expires:new Date(Date.now()+864e5*n.expires);o+=n.expires?"; expires="+u.toUTCString():""}o+=n.sameSite?"; sameSite="+n.sameSite:"",Object.isBoolean(n.secure)&&n.secure&&(o+=n.expires?"; secure":""),Object.isBoolean(n.httpOnly)&&n.httpOnly&&(o+=n.httpOnly?"; httpOnly":"")}return document.cookie=r+"="+i+o},e.prototype.get=function(e){for(var t=document.cookie?document.cookie.split("; "):[],n=0;n<t.length;n++){var r=t[n].split("="),i=decodeURIComponent(r[0]),o=r.slice(1).join("=");if(i===e)return'"'===o[0]&&(o=o.slice(1,-1)),o.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)}return null},e.prototype.delete=function(e,t){var n=t||{};n.expires=-1,this.set(e,"",n)},e}();Object.defineProperty(document,"fullScreen",{value:!1===Object.isUndefined(document.fullscreen)?document.fullscreen:!1===Object.isUndefined(document.mozFullScreen)?document.mozFullScreen:!1===Object.isUndefined(document.webkitIsFullScreen)?document.webkitIsFullScreen:!1===Object.isUndefined(document.msFullScreen)?document.msFullScreen:!1===Object.isUndefined(document.fullscreenElement)?null!==document.fullscreenElement:!1===Object.isUndefined(document.mozFullScreenElement)?null!==document.mozFullScreenElement:!1===Object.isUndefined(document.webkitFullscreenElement)?null!==document.webkitFullscreenElement:!1===Object.isUndefined(document.msFullscreenElement)&&null!==document.msFullscreenElement,configurable:!0,writable:!1}),Object.defineProperty(document,"fullScreenEnabled",{value:!1===Object.isUndefined(document.mozFullScreenEnabled)?document.mozFullScreenEnabled:!1===Object.isUndefined(document.webkitFullscreenEnabled)?document.webkitFullscreenEnabled:!1===Object.isUndefined(document.msFullscreenEnabled)?document.msFullscreenEnabled:!1===Object.isUndefined(document.fullscreenEnabled)&&document.fullscreenEnabled,configurable:!0,writable:!1}),Object.defineProperty(document,"fullScreenElement",{value:!1===Object.isUndefined(document.mozFullScreenElement)?document.mozFullScreenElement:!1===Object.isUndefined(document.webkitFullscreenElement)?document.webkitFullscreenElement:!1===Object.isUndefined(document.msFullscreenElement)?document.msFullscreenElement:!1===Object.isUndefined(document.fullscreenElement)?document.fullscreenElement:null,configurable:!0,writable:!1}),Object.defineProperty(document,"httpCookie",{value:new r,configurable:!0,writable:!1}),Document.prototype.requestFullscreen=function(){var e=document.documentElement;return Object.isFunction(e.mozRequestFullScreen)?e.mozRequestFullScreen():Object.isFunction(e.webkitRequestFullscreen)?e.webkitRequestFullscreen():Object.isFunction(e.msRequestFullscreen)?e.msRequestFullscreen():e.requestFullscreen()},Document.prototype.exitFullscreen=function(){return Object.isFunction(document.mozCancelFullScreen)?document.mozCancelFullScreen():Object.isFunction(document.mozExitFullScreen)?document.mozExitFullScreen():Object.isFunction(document.webkitCancelFullScreen)?document.webkitCancelFullScreen():Object.isFunction(document.webkitExitFullscreen)?document.webkitExitFullscreen():Object.isFunction(document.msExitFullscreen)?document.msExitFullscreen():document.exitFullscreen()},Function.prototype.argumentNames=function(){var e=this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/);if(null===e)return null;var t=e[1].replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g,"").replace(/\s+/g,"").split(", ");return 1!==t.length||t[0]?t:[]},Function.prototype.delay=function(e){var t=this,n=Array.prototype.slice.call(arguments,1);return window.setTimeout(t.apply(t,n),1e3*e)},Math.rand=function(e,t){e=e||0,t=t||Number.MAX_SAFE_INTEGER;var n=Math.random()*(t-e+1)+e;return(n=Math.round(n))<e?n=e:n>t&&(n=t),n},Number.prototype.toPaddedString=function(e,t){var n=this.toString(t||10);return"0".repeat(e-n.length)+n},Number.isOdd=function(e){return e%2==1},Number.isEven=function(e){return e%2==0},Number.isBetween=function(e,t,n,r){return void 0===r&&(r=!1),(t=t||0)>(n=n||0)&&(t^=n,t^=n^=t),1==r?e>=t&&e<=n:e>t&&e<n},String.prototype.exists=function(e){return this.indexOf(e)>=0},String.prototype.equals=function(e){return 0==Object.isUndefinedOrNull(e)&&this===e},String.prototype.equalsIgnoreCase=function(e){return null!=e&&this.toLowerCase()===e.toLowerCase()},String.prototype.isEmpty=function(){return 0===this.length},String.prototype.isNotEmpty=function(){return this.length>0},String.prototype.isBlank=function(){return/^\s*$/.test(this.toString())},String.prototype.repeat=function(e){if(e<1)return"";for(var t=this.toString(),n=0;n<e;n++)t+=this.toString();return t},String.prototype.left=function(e){return this.substring(0,e)},String.prototype.right=function(e){return this.substring(this.length-e,this.length)},String.prototype.truncation=function(e,t){return void 0===t&&(t="..."),t=t||"...",this.length>e?this.slice(0,e<=t.length?e:e-t.length)+t:String(this)},String.prototype.ltrim=function(){return Object.isFunction(this.trimStart)?this.trimStart():this.replace(/^\s*/g,"")},String.prototype.rtrim=function(){return Object.isFunction(this.trimEnd)?this.trimEnd():this.replace(/\s*$/g,"")},String.prototype.startsWith=function(e){return 0===this.indexOf(e)},String.prototype.endsWith=function(e){var t=this.length-e.length;return t>=0&&this.lastIndexOf(e)===t},String.prototype.lcfirst=function(){return this.charAt(0).toLowerCase()+this.substring(1)},String.prototype.ucfirst=function(){return this.charAt(0).toUpperCase()+this.substring(1)},String.prototype.escapeHTML=function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},String.prototype.unescapeHTML=function(){return this.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")},String.prototype.stripTag=function(e){return this.replace(new RegExp("<"+e+"(\\s+(\"[^\"]*\"|'[^']*'|[^>])+)?(/)?>|</"+e+">","gi"),"")},String.prototype.stripTags=function(e){if("string"==typeof e)return this.stripTag(e);if(Array.isArray(e)){for(var t=this.toString(),n=0;n<e.length;n++)t=t.stripTag(e[n]);return t}return this.toString()},String.prototype.stripScripts=function(){return this.replace(/<script[^>]*>([\S\s]*?)<\/script>/gim,"")},String.prototype.toArray=function(e){return this.split(e||"")},String.prototype.inspect=function(e){var t={"\b":"\\b","\t":"\\t","\r":"\\r","\n":"\\n","\f":"\\f","\\":"\\\\"},n=this.replace(/[\x00-\x1f\\]/g,(function(e){return e in t?t[e]:"\\u00"+e.charCodeAt(0).toPaddedString(2,16)}));return e?'"'+n.replace(/"/g,'\\"')+'"':"'"+n.replace(/'/g,"\\'")+"'"},String.prototype.hashCode=function(){var e=0;if(0===e&&this.length>0)for(var t=0;t<this.length;t++)e=31*e+this.charCodeAt(t);return e},String.random=function(e,t){void 0===t&&(t="LETTER_NUMERIC");var n="";if("CHINESE"===t){for(var r=0;r<e;r++)n+=String.fromCharCode(Math.rand(19968,40891));return n}var i="0123456789",o="abcdefghijklmnopqrstuvwxyz",u={NUMERIC:i,LETTER:o+o.toUpperCase(),LETTER_NUMERIC:i+o+o.toUpperCase()};if(!u[t])throw"Invalid argument type value, must be: NUMERIC, LETTER, LETTER_NUMERIC or CHINESE";for(var c=0;c<e;c++)n+=u[t].charAt(Math.rand(0,u[t].length-1));return n},Object.defineProperty(window,"browser",{value:{userAgent:navigator.userAgent,name:navigator.appName,version:navigator.appVersion,isMobile:["Android","iPhone","iPod","Windows Phone","Mobile","Coolpad","mmp","SmartPhone","midp","wap","xoom","Symbian","J2ME","Blackberry","Wince"].some((function(e){return navigator.userAgent.exists(e)})),isChrome:/\(KHTML, like Gecko\) Chrome\//.test(navigator.userAgent),isFirefox:navigator.userAgent.exists("Firefox"),isMozilla:navigator.userAgent.exists("Mozilla"),isEdge:navigator.userAgent.exists("Edge"),isMSIE:navigator.userAgent.exists("MSIE")&&navigator.userAgent.exists("compatible"),isOpera:navigator.userAgent.exists("Opera"),isSafari:navigator.userAgent.exists("Safari"),isNetscape:/Netscape([\d]*)\/([^\s]+)/i.test(navigator.userAgent)},configurable:!0,writable:!1}),Window.prototype.copy=function(e){try{if(Object.isObject(this.clipboardData))this.clipboardData.setData("text",e);else{var t=document.createElement("textarea");t.style.border="none",t.style.margin="0",t.style.padding="0",t.style.position="absolute",t.style.top="-9999px",t.style.left="-9999px",t.value=e,t.setAttribute("readonly",""),document.body.appendChild(t),t.setSelectionRange(0,e.length),t.select(),document.execCommand("copy"),t.remove()}}catch(e){console.error(e)}},Location.prototype.getParameters=function(){var e=this.search,t=new Object;if(-1!=e.indexOf("?"))for(var n=(e=e.substring(1)).split("&"),r=0;r<n.length;r++){var i=n[r].split("="),o=2==i.length?encodeURIComponent(i[1]):"";if(Object.isUndefined(t[i[0]]))t[i[0]]=o;else{if(0==Object.isArray(t[i[0]])){var u=t[i[0]];delete t[i[0]],t[i[0]]=[u]}t[i[0]].push(o)}}return t},Location.prototype.getParameter=function(e){return this.getParameters()[e]}}();
11//# sourceMappingURL=prototype.iife.min.js.map