2 lines
22 KiB
JavaScript
Executable File
2 lines
22 KiB
JavaScript
Executable File
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("lib/fetch.js",t):(e="undefined"!=typeof globalThis?globalThis:e||self).KSAdWKJSBridge=t()}(this,function(){"use strict";var t,o,s="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||void 0!==s&&s,c={searchParams:"URLSearchParams"in s,iterable:"Symbol"in s&&"iterator"in Symbol,blob:"FileReader"in s&&"Blob"in s&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in s,arrayBuffer:"ArrayBuffer"in s};function r(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function d(e){return e="string"!=typeof e?String(e):e}function e(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return c.iterable&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach(function(e,t){this.append(t,e)},this):Array.isArray(t)?t.forEach(function(e){this.append(e[0],e[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function n(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function a(o){return new Promise(function(e,t){o.onload=function(){e(o.result)},o.onerror=function(){t(o.error)}})}function i(e){var t=new FileReader,o=a(t);return t.readAsArrayBuffer(e),o}function u(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function f(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,(this._bodyInit=e)?"string"==typeof e?this._bodyText=e:c.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:c.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:c.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():c.arrayBuffer&&c.blob&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=u(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):c.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||o(e))?this._bodyArrayBuffer=u(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):c.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},c.blob&&(this.blob=function(){var e=n(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=n(this);return e?e:ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer)}return this.blob().then(i)}),this.text=function(){var e,t,o=n(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,o=a(t),t.readAsText(e),o;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),o=new Array(t.length),r=0;r<t.length;r++)o[r]=String.fromCharCode(t[r]);return o.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},c.formData&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}c.arrayBuffer&&(t=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(e){return e&&-1<t.indexOf(Object.prototype.toString.call(e))}),l.prototype.append=function(e,t){e=r(e),t=d(t);var o=this.map[e];this.map[e]=o?o+", "+t:t},l.prototype.delete=function(e){delete this.map[r(e)]},l.prototype.get=function(e){return e=r(e),this.has(e)?this.map[e]:null},l.prototype.has=function(e){return this.map.hasOwnProperty(r(e))},l.prototype.set=function(e,t){this.map[r(e)]=d(t)},l.prototype.forEach=function(e,t){for(var o in this.map)this.map.hasOwnProperty(o)&&e.call(t,this.map[o],o,this)},l.prototype.keys=function(){var o=[];return this.forEach(function(e,t){o.push(t)}),e(o)},l.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),e(t)},l.prototype.entries=function(){var o=[];return this.forEach(function(e,t){o.push([t,e])}),e(o)},c.iterable&&(l.prototype[Symbol.iterator]=l.prototype.entries);var h=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function p(e,t){if(!(this instanceof p))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var o,r=(t=t||{}).body;if(e instanceof p){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new l(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,r||null==e._bodyInit||(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new l(t.headers)),this.method=(o=t.method||this.method||"GET",e=o.toUpperCase(),-1<h.indexOf(e)?e:o),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r),"GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache||((t=/([?&])_=[^&]*/).test(this.url)?this.url=this.url.replace(t,"$1_="+(new Date).getTime()):this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime())}function y(e){var o=new FormData;return e.trim().split("&").forEach(function(e){var t;e&&(e=(t=e.split("=")).shift().replace(/\+/g," "),t=t.join("=").replace(/\+/g," "),o.append(decodeURIComponent(e),decodeURIComponent(t)))}),o}function b(e,t){if(!(this instanceof b))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t=t||{},this.type="default",this.status=void 0===t.status?200:t.status,this.ok=200<=this.status&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new l(t.headers),this.url=t.url||"",this._initBody(e)}p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},f.call(p.prototype),f.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},b.error=function(){var e=new b(null,{status:0,statusText:""});return e.type="error",e};var m=[301,302,303,307,308];b.redirect=function(e,t){if(-1===m.indexOf(t))throw new RangeError("Invalid status code");return new b(null,{status:t,headers:{location:e}})};var g=s.DOMException;try{new g}catch(e){(g=function(e,t){this.message=e,this.name=t;e=Error(e);this.stack=e.stack}).prototype=Object.create(Error.prototype),g.prototype.constructor=g}function w(r,i){return new Promise(function(n,e){var t=new p(r,i);if(t.signal&&t.signal.aborted)return e(new g("Aborted","AbortError"));var a=new XMLHttpRequest;function o(){a.abort()}a.onload=function(){var e,o,t={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",o=new l,e.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e}).forEach(function(e){var t=e.split(":"),e=t.shift().trim();e&&(t=t.join(":").trim(),o.append(e,t))}),o)};t.url="responseURL"in a?a.responseURL:t.headers.get("X-Request-URL");var r="response"in a?a.response:a.responseText;setTimeout(function(){n(new b(r,t))},0)},a.onerror=function(){setTimeout(function(){e(new TypeError("Network request failed"))},0)},a.ontimeout=function(){setTimeout(function(){e(new TypeError("Network request failed"))},0)},a.onabort=function(){setTimeout(function(){e(new g("Aborted","AbortError"))},0)},a.open(t.method,function(t){try{return""===t&&s.location.href?s.location.href:t}catch(e){return t}}(t.url),!0),"include"===t.credentials?a.withCredentials=!0:"omit"===t.credentials&&(a.withCredentials=!1),"responseType"in a&&(c.blob?a.responseType="blob":c.arrayBuffer&&t.headers.get("Content-Type")&&-1!==t.headers.get("Content-Type").indexOf("application/octet-stream")&&(a.responseType="arraybuffer")),!i||"object"!=typeof i.headers||i.headers instanceof l?t.headers.forEach(function(e,t){a.setRequestHeader(t,e)}):Object.getOwnPropertyNames(i.headers).forEach(function(e){a.setRequestHeader(e,d(i.headers[e]))}),t.signal&&(t.signal.addEventListener("abort",o),a.onreadystatechange=function(){4===a.readyState&&t.signal.removeEventListener("abort",o)}),a.send(void 0===t._bodyInit?null:t._bodyInit)})}w.polyfill=!0;var v=s.Headers,S=s.Request,A=s.Response,k=s.fetch;function B(e){k&&(e?(s.fetch=w,s.Headers=l,s.Request=p,s.Response=b):(s.fetch=k,s.Headers=v,s.Request=S,s.Response=A))}s.fetch||(s.fetch=w,s.Headers=l,s.Request=p,s.Response=b);var T=(H.setupHook=function(){var e=window.FormData.prototype.append;window.FormData.prototype.entries||(window.FormData.prototype.append=function(){return this._entries||(this._entries=[]),this._entries.push(arguments),e.apply(this,arguments)})},H.traversalEntries=function(e,t){var o,r;if(e._entries)for(var n=0;n<e._entries.length;n++){var a=(l=e._entries[n])[0],i=l[1],s=2<l.length?l[2]:null;t&&t(a,i,s)}else try{for(var c=function(e){var t="function"==typeof Symbol&&Symbol.iterator,o=t&&e[t],r=0;if(o)return o.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&r>=e.length?void 0:e)&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(e.entries()),d=c.next();!d.done;d=c.next()){var l,a=(l=d.value)[0],i=l[1];t&&t(a,i,null)}}catch(e){o={error:e}}finally{try{d&&!d.done&&(r=c.return)&&r.call(c)}finally{if(o)throw o.error}}},H);function H(){}var C=(x.convertArrayBufferToBase64=function(e){for(var t=new Uint8Array(e),o="",r=t.byteLength,n=0;n<r;n++)o+=String.fromCharCode(t[n]);return window.btoa(o)},x.convertFormDataToJson=function(e,i){var r=[];T.traversalEntries(e,function(e,t,o){r.push(x.convertSingleFormDataRecordToArray(e,t,o))}),Promise.all(r).then(function(e){for(var t={},o=[],r=0;r<e.length;r++){var n=e[r],a=n[1];1<n.length&&x.isObject(a)&&o.push(n[0])}t.fileKeys=o,t.formData=e,i(t)}).catch(function(e){console.log(e)})},x.convertSingleFormDataRecordToArray=function(n,a,i){return new Promise(function(t,o){var e,r=[];r.push(n),a instanceof File||a instanceof Blob?((e=new FileReader).readAsDataURL(a),e.onload=function(e){e=e.target.result,e={name:i||(a instanceof File?a.name:""),lastModified:a instanceof File?a.lastModified:0,size:a.size,type:a.type,data:e};return r.push(e),t(r),null},e.onerror=function(e){return o(Error("formdata 表单读取文件数据失败")),null}):(r.push(a),t(r))})},x.convertFileToJson=function(r){return new Promise(function(t,o){var e=new FileReader;e.readAsDataURL(r),e.onload=function(e){e=e.target.result,e={name:r instanceof File?r.name:"",lastModified:r instanceof File?r.lastModified:0,size:r.size,type:r.type,data:e};return t(e),null},e.onerror=function(e){return o(Error("formdata 表单读取文件数据失败")),null}})},x.isType=function(e){return Object.prototype.toString.call(e)},x.isObject=function(e){return"[object Object]"===x.isType(e)},x.isEncodedString=function(e){return"string"==typeof e&&0<e.length&&decodeURIComponent(e)!==e},x);function x(){}var E=(K.dispatchMessage=function(e){var t=document.querySelectorAll("iframe");if(t)for(var o=t.length,r=0;r<o;r++)t[r].contentWindow.postMessage(e,"*")},K.addMessageListener=function(){window.addEventListener("message",function(e){e=e.data;"string"!=typeof e||-1!=(e=e).indexOf("messageType")&&window.KSAdWKJSBridge._handleMessageFromNative(e)})},K.addAjaxMessageListener=function(){window.addEventListener("message",function(e){e=e.data;"string"!=typeof e||-1!=(e=e).indexOf("ajaxType")&&window._KSAdWKJSBridgeXHR.setProperties(e)})},K.setupHook=function(){document.addEventListener("DOMContentLoaded",function(){var e=document.querySelectorAll("iframe");if(e)for(var t=e.length,o=0;o<t;o++){var r=e[o];r.getAttribute("sandbox")&&-1==r.getAttribute("sandbox").indexOf("allow-scripts")&&r.setAttribute("sandbox",r.getAttribute("sandbox")+" allow-scripts")}});var r=document.createElement;document.createElement=function(e){var t=r.call(document,e);if("iframe"===e.toLowerCase())try{var o=Object.getOwnPropertyDescriptor(window.HTMLIFrameElement,"sandbox")||Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype,"sandbox");o&&o.configurable&&Object.defineProperty(t,"sandbox",{configurable:!0,enumerable:!0,get:function(){return o.get.call(t)},set:function(e){-1==e.indexOf("allow-scripts")&&(e+=" allow-scripts"),o.set.call(t,e)}})}catch(e){console.log("this browser does not support reconfigure iframe sandbox property",e)}return t}},K);function K(){}var O=(R.prototype.callNative=function(e,t,o,r){o={module:e||"default",method:t,data:o,callbackId:null};r&&(t="cb_"+o.module+"_"+t+"_"+this.uniqueId+++"_"+(new Date).getTime(),this.callbackCache[t]=r,o.callbackId=t),window.webkit.messageHandlers.KSAdWKJSBridgeMessage.postMessage(o)},R.prototype._handleMessageFromNative=function(e){var t=JSON.parse(e);if("callback"===t.messageType){var o=this.callbackCache[t.callbackId];o&&(o(t.data),this.callbackCache[t.callbackId]=null,delete this.callbackCache[t.callbackId])}else if("event"===t.messageType){var r=this.eventCallbackCache[t.eventName];if(r)for(var n=0;n<r.length;n++){var a=r[n];a&&a(t.data)}}E.dispatchMessage(e)},R.prototype.call=function(e,t,o,r){this.callNative(e,t,o,r)},R.prototype.syncCall=function(o,r,n){try{return function(){var e,t=JSON.stringify({module:o||"default",method:r,data:n}),t=window.prompt("KSAdWKJSBridge",t);try{e=JSON.parse(t)}catch(e){console.log("syncCall json parse failecd",e)}return t?e:null}()}catch(e){return console.log("window.prompt will happen error when beforeunload event triggered",e),null}},R.prototype.on=function(e,t){var o=this.eventCallbackCache[e];o?o.push(t):this.eventCallbackCache[e]=o=[t]},R.prototype.off=function(e){e=this.eventCallbackCache[e];e&&0<e.length&&e.splice(0,e.length)},R);function R(){this.uniqueId=1,this.callbackCache={},this.eventCallbackCache={}}var q=(j.ready=function(){window.KSAdWKJSBridge.call(j.moduleName,"bridgeReady",{})},j.moduleName="cookie",j.setupHook=function(){try{var n=Object.getOwnPropertyDescriptor(Document.prototype,"cookie")||Object.getOwnPropertyDescriptor(HTMLDocument.prototype,"cookie");n&&n.configurable&&Object.defineProperty(document,"cookie",{configurable:!0,enumerable:!0,get:function(){var e=n.get.call(document);return window.KSAdWKJSBridgeConfig.cookieHook&&window.KSAdWKJSBridgeConfig.ajaxHook&&window.KSAdWKJSBridgeConfig.ajaxSyncHook&&window.KSAdWKJSBridgeConfig.cookieGetHook?window.KSAdWKJSBridge.syncCall(j.moduleName,"cookie",{url:window.location.href}).cookie:e},set:function(t){if(window.KSAdWKJSBridgeConfig.cookieHook)if(window.KSAdWKJSBridgeConfig.ajaxHook){try{var e,o,r;/;\s*path\s*=/i.test(t)||(o=(e=(e=document.location.pathname).substring(0,e.lastIndexOf("/")))?"; path="+e:"; path=/",(t=t.endsWith(";")?t.substring(0,t.indexOf(";")):t).includes(";")?/;\s*domain\s*=/i.test(t)?t=t.replace(/;\s*domain\s*=/i,o+"; domain="):/;\s*expires\s*=/i.test(t)?t=t.replace(/;\s*expires\s*=/,o+"; expires="):/;\s*HTTPOnly/i.test(t)?t=t.replace(/;\s*HTTPOnly/i,o+"; HTTPOnly"):/;\s*Secure/i.test(t)?t=t.replace(/;\s*Secure/i,o+"; Secure"):/;\s*SameSite/i.test(t)&&(t=t.replace(/;\s*SameSite/i,o+"; SameSite")):t+=o),/;\s*domain\s*=/i.test(t)||!/;\s*path\s*=/i.test(t)||(r=document.location.hostname)&&(t=t.replace(/;\s*path\s*=\s*/i,"; domain=."+r+"; path=")),window.KSAdWKJSBridgeConfig.ajaxSyncHook&&!/;\s*domain\s*=\s*\.[A-Za-z0-9]/i.test(t)&&/;\s*domain\s*=\s*[A-Za-z0-9]/i.test(t)&&(t=t.replace(/;\s*domain\s*=\s*/i,"; domain=."))}catch(e){console.log("this browser does not support includes/replace API(<iOS9)",e)}window.KSAdWKJSBridgeConfig.ajaxSyncHook&&window.KSAdWKJSBridgeConfig.cookieSetSyncHook?window.KSAdWKJSBridge.syncCall(j.moduleName,"setCookie",{cookie:t})&&n.set.call(document,t):window.KSAdWKJSBridgeConfig.ajaxSyncHook?window.KSAdWKJSBridge.call(j.moduleName,"setCookie",{cookie:t},function(e){e&&n.set.call(document,t)}):(n.set.call(document,t),window.KSAdWKJSBridge.call(j.moduleName,"setCookie",{cookie:t}))}else n.set.call(document,t);else n.set.call(document,t)}})}catch(e){console.log("this browser does not support reconfigure document.cookie property",e)}},j);function j(){}var _=(F.moduleName="ajax",F.globalId=Math.floor(1e5*Math.random()),F.callbackCache=[],F.generateXHRRequestId=function(){return(new Date).getTime()+""+F.globalId++},F.generateNewActionForForm=function(e,t){var o=e.action;e.action=F.generateNewUrlWithRequestId(o,t)},F.generateNewUrlWithRequestId=function(e,t){var o=e,r=document.createElement("a");r.href=o,r.search,r.hash;var n=document.createElement("a");n.href=o,n.search="",n.hash="","#"===(e=n.href).trim()&&(e="");try{e.endsWith("?")&&(e=e.replace("?",""))}catch(e){console.log("this browser does not support endsWith API(<iOS9)",e)}return e+r.search+r.hash},F.generateNewOpenUrlWithRequestId=function(e,t){function o(e){return"^^^^"+e+"^^^^"}var r=/\^\^\^\^(\d+)\^\^\^\^/,n=document.createElement("a");n.href=e;var a=n.hash||"";return r.test(n.hash)?n.hash=n.hash.replace(r,o(t)):n.hash&&0<n.hash.length?n.hash=n.hash+o(t):n.hash=o(t),(e="#"===(e=e.replace(a,"")).trim()?"":e)+n.hash},F.isNonNormalHttpRequest=function(e,t){var o=!1;try{(e.includes("http://")||e.includes("https://"))&&(o=!0)}catch(e){console.log("this browser does not support includes API(<iOS9)",e)}return!/^((http|https):\/\/)/.test(e)&&("GET"===t||"GET"===t.toUpperCase())&&o},F.isBodyAvailableHttpRequest=function(e){var t=["POST","PUT","DELETE","PATCH","LOCK","PROPFIND","SEARCH"];return-1<t.indexOf(e)||-1<t.indexOf(e.toUpperCase())},F.sendBodyToNativeForCache=function(e,t,o,r,n,a){var i=t.requestId,s={requestId:i,callback:function(){return"AJAX"===e&&t.setRequestHeader("KSAdWKJSBridge-RequestId",i),"FORM"===e&&F.generateNewActionForForm(t,i),o.apply(t,r)}};if(a=void 0===a?!0:a)return F.callbackCache[i]=s,void window.KSAdWKJSBridge.call(F.moduleName,"cacheAJAXBody",n,function(e){var t=e.requestId;F.callbackCache[t]&&((e=F.callbackCache[t])&&e.callback&&"function"==typeof e.callback&&e.callback(),delete F.callbackCache[t])});window.KSAdWKJSBridgeConfig.ajaxSyncHook?(window.KSAdWKJSBridge.syncCall(F.moduleName,"cacheAJAXBody",n),s.callback()):(console.log("[ERROR]本版本不支持同步请求或者未开启同步请求功能, 请联系Yoda团队(chenyilong@kuaishou.com)进行处理。"),F.callbackCache[i]=s,window.KSAdWKJSBridge.call(F.moduleName,"cacheAJAXBody",n,function(e){var t=e.requestId;F.callbackCache[t]&&((e=F.callbackCache[t])&&e.callback&&"function"==typeof e.callback&&e.callback(),delete F.callbackCache[t])}))},F.setupHook=function(){var s=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(e,t,o,r,n){var a=[].slice.call(arguments),i=this;return i.requestId=F.generateXHRRequestId(),i.requestUrl=t,i.requestHref=document.location.href,i.requestMethod=e,i.requestAsync=o,!F.isNonNormalHttpRequest(t,e)&&window.KSAdWKJSBridgeConfig.ajaxHook?(a[1]=F.generateNewUrlWithRequestId(t,i.requestId),void s.apply(i,a)):s.apply(i,a)};var a=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.send=function(e){var t=[].slice.call(arguments),o=this,r={requestId:o.requestId,requestHref:o.requestHref,requestUrl:o.requestUrl,bodyType:"String",value:null};if(F.isNonNormalHttpRequest(o.requestUrl,o.requestMethod))return a.apply(o,t);if(!F.isBodyAvailableHttpRequest(o.requestMethod))return a.apply(o,t);if(!window.KSAdWKJSBridgeConfig.ajaxHook)return a.apply(o,t);if(!e)return a.apply(o,t);if(e instanceof ArrayBuffer)r.bodyType="ArrayBuffer",r.value=C.convertArrayBufferToBase64(e);else{if(e instanceof Blob){r.bodyType="Blob";var n=new FileReader;return n.onload=function(e){e=e.target.result;r.value=e,F.sendBodyToNativeForCache("AJAX",o,a,t,r)},void n.readAsDataURL(e)}if(e instanceof FormData)return r.bodyType="FormData",r.formEnctype="multipart/form-data",void C.convertFormDataToJson(e,function(e){r.value=e,F.sendBodyToNativeForCache("AJAX",o,a,t,r)});r.bodyType="String",r.value=e}F.sendBodyToNativeForCache("AJAX",o,a,t,r,o.requestAsync)};var n=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){var t=[].slice.call(arguments),o=this;o.requestId=F.generateXHRRequestId(),o.requestUrl=o.action,o.requestHref=document.location.href;var r={requestId:o.requestId,requestHref:o.requestHref,requestUrl:o.requestUrl,bodyType:"FormData",formEnctype:o.enctype,value:null};if(!window.KSAdWKJSBridgeConfig.ajaxHook)return n.apply(o,t);if(!o.action)return n.apply(o,t);var e=new FormData(o);C.convertFormDataToJson(e,function(e){r.value=e,F.sendBodyToNativeForCache("FORM",o,n,t,r)})}},F);function F(){}var I;function P(){}return window.KSAdWKJSBridge||(P.ajaxHook=!0,P.cookieSetHook=!0,P.cookieHook=!0,P.cookieGetHook=!1,P.ajaxSyncHook=!1,P.cookieSetSyncHook=!1,P.ajaxBodyCacheLimit=!1,P.enableAjaxHook=function(e){e?(P.cookieSetHook=!0,P.ajaxHook=!0,B(P.cookieHook=!0)):(P.cookieSetHook=!1,P.ajaxHook=!1,B(P.cookieHook=!1))},P.enableCookieSetHook=function(e){P.cookieSetHook=e},P.enableCookieSetSyncHook=function(e){P.cookieSetSyncHook=e},P.enableCookieGetHook=function(e){P.cookieGetHook=e},P.enableAjaxSyncHook=function(e){P.ajaxSyncHook=e},P.enableCookieHook=function(e){P.cookieHook=e},P.enableAjaxBodyCacheLimit=function(e){P.ajaxBodyCacheLimit=e},P.bridgeReady=function(){q.ready();var e=document.createEvent("Events");e.initEvent("KSAdWKJSBridgeReady"),document.dispatchEvent(e)},I=P,window.KSAdWKJSBridge=new O,window.KSAdWKJSBridgeConfig=I,window._KSAdWKJSBridgeXHR=_,E.addMessageListener(),E.setupHook(),T.setupHook(),q.setupHook(),_.setupHook(),window.KSAdWKJSBridgeConfig.bridgeReady()),window.KSAdWKJSBridge});
|