forked from 999dici/FoxTools.Lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoxtools.lib.min.js
More file actions
23 lines (23 loc) · 18.2 KB
/
foxtools.lib.min.js
File metadata and controls
23 lines (23 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*! Хитрая библиотека для работы с не менее Хитрым API v2.0
* http://api.foxtools.ru/v2
* http://foxtools.ru
*
* Версия библиотеки: 1.0.2 (17 мая 2015 года)
* ----------------------------------------------------------------------------
* Copyright (c) Aleksey Nemiro, 2015. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ----------------------------------------------------------------------------
*/
var __extends=this.__extends||function(n,t){function r(){this.constructor=n}for(var i in t)t.hasOwnProperty(i)&&(n[i]=t[i]);r.prototype=t.prototype;n.prototype=new r},foxtools;(function(n){function r(t,i){n.lib.client.foxyForm(t,i)}function u(t){return new n.lib.request(t)}var i,t;(function(i){var u=function(){function n(){}return n.tokenCookieName="foxtoken",n.requestBaseUrl="{0}://api.foxtools.ru/v2/{1}",n.useSsl=!1,n}(),e,r,it,s,v,rt,y,p,f,h,c,w,b,o,k,d,g,nt,ut,ft,tt,et,l,a,st,ht,ot,ct;i.config=u;e=function(){function n(){this.token=null}return n}();i.requestProcess=e;r=function(){function t(n){if(this.messages=[],this.trace=[],n===undefined||n===null||n==="")throw new Error("Type is required.");this.type=n}return t.prototype.addTrace=function(t,i){this.trace.push(new b(t,i));console.log(n.utility.format("TRACE: {0} - {1}",[t,i]))},t.prototype.addMessage=function(t,i){this.messages.push(new w(t,i));console.log(n.utility.format("{0}: {1}",[t,i]))},t}();i.baseResult=r;it=function(){function n(){}return n.getToken=function(n,i){var r=null;if(typeof n=="object"&&(i===undefined&&i===null?i=n:$.extend(i,n),n=i.url),i=i||{},!(r=t.readCookies(u.tokenCookieName))){if(n===undefined||n===null)return console.log("Url is empty. No way to get a new token..."),r;$.ajax({type:i.type||"POST",enctype:i.enctype||"application/x-www-form-urlencoded",url:n,success:function(n){typeof n=="object"&&(n=n.token!==undefined&&n.token!==null&&typeof n.token=="string"?n.token:n.value!==undefined&&n.value!==null&&typeof n.value=="string"?n.value:n.data!==undefined&&n.data!==null&&typeof n.data=="string"?n.data:n[Object.keys(n)[0]]);t.createCookies(u.tokenCookieName,n);i.complete!==undefined&&i.complete!==null&&typeof i.complete=="function"&&i.complete(new o(n))},error:function(n,t,r){i.complete!==undefined&&i.complete!==null&&typeof i.complete=="function"?i.complete(new h(new c(0,t+": "+r))):console.log(t+": "+r)}})}return r},n.foxyForm=function(n,t){$(n).length<=0||$(n).each(function(){this.tagName.toLowerCase()=="form"?$(this).submit(function(){t=t||new e;var n=new v(this);return n.token=t.token,n.complete=t.complete,n.begin=t.begin,n.uploading=t.uploading,$(this).data("begin")!==undefined&&$(this).data("begin")!==""&&typeof window[$(this).data("begin")]=="function"&&(n.begin=window[$(this).data("begin")]),$(this).data("complete")!==undefined&&$(this).data("complete")!==""&&typeof window[$(this).data("complete")]=="function"&&(n.complete=window[$(this).data("complete")]),$(this).data("token")!==undefined&&$(this).data("token")!==""&&(n.token=$(this).data("token")),n.submit(),!1}):console.log("WARNING: Expected a form tag.")})},n.ready=function(){a.init()},n}();i.client=it;s=function(){function n(n,t){this.request=null;this.token=null;this.cancel=!1;this.request=n;this.token=t}return n}();i.beginRequest=s;v=function(i){function r(n){i.call(this);this.form=null;this.form=n}return __extends(r,i),r.prototype.submit=function(){var r=this,i=l.parse(r.token);i!==null&&i.url!==null&&i.value===null&&(i.value=t.readCookies(u.tokenCookieName));i!==null&&i.url!==null&&i.value===null?n.lib.client.getToken(i.url,{type:r.token.type,enctype:r.token.enctype,complete:function(n){if(n.type=="errorResult")throw new Error(n.getText());else i.value=n.value,r.justSubmit(i)}}):r.justSubmit(i)},r.prototype.justSubmit=function(n){var i=this,o=i.form,r=$(i.form),h=r.attr("method")||"GET",c,e,l,v;if($("input[type=file]",o).length>0&&(h="POST"),c=null,n!==null&&n.value!==null&&n.value!=""&&(c={Authorization:"Bearer "+n.value}),e=$(r.attr("action").split("/")).last()[0].toString(),e=e.indexOf("?")!=-1?e.substr(0,e.indexOf("?")):e,i.begin!==undefined&&i.begin!==null&&typeof i.begin=="function"){if(l=new s(i,n),i.begin(l),l.cancel)return;o=i.form;r=$(o)}v=null;v=h.toUpperCase()=="POST"?new window.FormData(o):r.serialize();a.hit(r.attr("action"),e);$.ajax({type:h,url:r.attr("action"),data:v,dataType:"json",headers:c,xhr:function(){var n=$.ajaxSettings.xhr();return n.upload&&n.upload.addEventListener("progress",function(n){n.lengthComputable&&i.uploading!==undefined&&i.uploading!==null&&typeof i.uploading=="function"&&i.uploading(Math.round(n.loaded*100/n.total),n.loaded,n.total)},!1),n},beforeSend:function(){r.removeData("completed");r.data("sending","true")},success:function(n){i.complete!==undefined&&i.complete!==null&&typeof i.complete=="function"?i.complete(new f(e,200,null,n)):new f(e,200,null,n)},error:function(r,o,s){var h=new f(e,r.status,s,$.parseJSON(r.responseText||s));if(h.data.type=="errorResult"&&$.grep(h.data.items,function(n){return n.code==1110||n.code==1111||n.code==1112}).length>0&&n.url!==null&&n.errors==0){t.eraseCookies(u.tokenCookieName);i.token={url:n.url,errors:n.errors+1};i.submit();return}i.complete!==undefined&&i.complete!==null&&typeof i.complete=="function"&&i.complete(h)},complete:function(){r.removeData("sending");r.data("completed","true")},cache:!1,processData:!1,contentType:!1})},r}(e);i.formRequest=v;rt=function(i){function r(n){if(i.call(this),this.baseUrl=u.requestBaseUrl,this.useSsl=u.useSsl,this.type="GET",this.endpoint="",this.methodName="",n===undefined||n===null)throw new Error("Method name is required. Please add method name to request:\r\nYou can find a list of methods on the page: http://api.foxtools.ru/v2");this.methodName=n;this.endpoint=t.format(this.baseUrl,[this.useSsl?"https":"http",n]);this.parameters=new y}return __extends(r,i),r.prototype.execute=function(){var r=this,i=l.parse(r.token);i!==null&&i.url!==null&&i.value===null&&(i.value=t.readCookies(u.tokenCookieName));i!==null&&i.url!==null&&i.value===null?n.lib.client.getToken(i.url,{type:r.token.type,enctype:r.token.enctype,complete:function(n){if(n.type=="errorResult")throw new Error(n.getText());else i.value=n.value,r.justExecute(i)}}):r.justExecute(i)},r.prototype.justExecute=function(n){var i=this,r=i.type||"GET",e,o,h;(i.parameters.hasFiles&&(r="POST"),e=null,n!==null&&n.value!==null&&n.value!=""&&(e={Authorization:"Bearer "+n.value}),i.begin!==undefined&&i.begin!==null&&typeof i.begin=="function"&&(o=new s(i,n),i.begin(o),o.cancel))||(h=i.parameters.toParams(r),a.hit(i.endpoint,i.methodName),$.ajax({url:i.endpoint,type:r,headers:e,xhr:function(){var n=$.ajaxSettings.xhr();return n.upload&&n.upload.addEventListener("progress",function(n){n.lengthComputable&&i.uploading!==undefined&&i.uploading!==null&&typeof i.uploading=="function"&&i.uploading(Math.round(n.loaded*100/n.total),n.loaded,n.total)},!1),n},success:function(n){i.complete!==undefined&&i.complete!==null&&typeof i.complete=="function"?i.complete(new f(i.methodName,200,null,n)):new f(i.methodName,200,null,n)},error:function(r,e,o){var s=new f(i.methodName,r.status,o,$.parseJSON(r.responseText||o));if(s.data.type=="errorResult"&&$.grep(s.data.items,function(n){return n.code==1110||n.code==1111||n.code==1112}).length>0&&n.url!==null&&n.errors==0){t.eraseCookies(u.tokenCookieName);i.token={url:n.url,errors:n.errors+1};i.execute();return}i.complete!==undefined&&i.complete!==null&&typeof i.complete=="function"&&i.complete(s)},complete:function(){},data:h,cache:!1,contentType:!1,processData:!1}))},r}(e);i.request=rt;y=function(){function n(){this.items=[]}return n.prototype.add=function(n,t){this.items.push(new p(n,t))},n.prototype.toParams=function(n){var i,t,r;for((this.hasFiles||n===undefined||n===null)&&(n="POST"),n=n.toUpperCase(),i=null,i=n=="POST"?new FormData:{},t=0;t<=this.items.length-1;t++)if(n=="POST")if(this.items[t].isFile)if(this.items[t].value.length==1&&i.append(this.items[t].name,this.items[t].value[0]),this.items[t].value.length>1)for(r=0;r<=this.items[t].value.length-1;r++)i.append(this.items[t].name+"[]",this.items[t].value[r]);else i.append(this.items[t].name,null);else i.append(this.items[t].name,this.items[t].value);else i[this.items[t].name]=this.items[t].value;return n=="POST"?i:$.param(i)},Object.defineProperty(n.prototype,"hasFiles",{get:function(){return $.grep(this.items,function(n){if(n.isFile)return!0}).length>0},enumerable:!0,configurable:!0}),n}();i.httpParameterCollection=y;p=function(){function n(n,i){if(this.isFile=!1,n===undefined||n===null)throw new Error("Name is required.");if(t.isElement(n))this.name=$(n).attr("name"),this.setValue(n);else if(t.isJqueryObject(n))if(n.length)this.name=n.attr("name"),this.setValue(n);else throw new Error("jQuery object can not be empty.");else this.name=n.toString(),this.setValue(i)}return n.prototype.setValue=function(n){if(t.isElement(n))n=$(n);else if(t.isJqueryObject(n)){if(!n.length)throw new Error("jQuery object can not be empty.");}else{this.isFile=!1;this.value=n;return}n.is(":file")?(this.isFile=!0,this.value=n[0].files):(this.isFile=!1,this.value=n.val())},n}();i.httpParameter=p;f=function(){function n(n,t,i,r){var u;if(t===0?r.response.errors.items=[{code:0,text:"Not connect. Verify Network."}]:t==404?r.response.errors.items=[{code:0,text:"Requested page not found [HTTP404]."}]:i==="parsererror"?r.response.errors.items=[{code:0,text:"Requested JSON parse failed."}]:i==="timeout"?r.response.errors.items=[{code:0,text:"Timeout error."}]:i==="abort"&&(r.response.errors.items=[{code:0,text:"Ajax request aborted."}]),r!==undefined&&r!==null){if(this.methodName=n!==undefined&&n!==null?n.toLowerCase():"",typeof r=="object"){if(r.response===undefined||r.response===null)return;r=r.response}else{this.data=new o(r);return}if(r.errors!==undefined&&r.errors!==null)this.data=new h(r.errors);else switch(this.methodName){case"geoip":this.data=new nt(r);break;case"hash":this.data=new d(r.items);break;case"proxy":this.data=new tt(r);break;case"machinekey":case"stat":case"textdecoder":case"translator":case"weather":case"webconverter":case"eventlogger":this.data=r;break;case"pwd":case"guid":case"idn":case"randomkey":this.data=new k(r);break;default:this.data=new o(r.value)}if(r.messages!==undefined&&r.messages!==null)for(u=0;u<=r.messages.length-1;u++)this.data.addMessage(r.messages[u].type,r.messages[u].text);if(r.trace!==undefined&&r.trace!==null)for(u=0;u<=r.trace.length-1;u++)this.data.addTrace(r.trace[u].message,r.trace[u].elapsedTime)}}return Object.defineProperty(n.prototype,"isError",{get:function(){return this.data.type==="errorResult"},enumerable:!0,configurable:!0}),n.prototype.toString=function(){return this.data.toString()},n}();i.result=f;h=function(n){function t(t){if(n.call(this,"errorResult"),this.items=[],t!==undefined&&t!==null)for(var i=0;i<=t.length-1;i++)this.add(ot[t[i].code],t[i].text)}return __extends(t,n),t.prototype.add=function(n,t){this.items.push(new c(n,t))},t.prototype.toString=function(){return this.getText()},t.prototype.getText=function(){for(var n="",t=0;t<=this.items.length-1;t++)n.length>0&&(n+="\n"),n+=this.items[t].text;return n},t}(r);i.errorResult=h;c=function(){function n(n,t){this.code=n;this.text=t}return n}();i.errorMessage=c;w=function(){function n(n,t){this.type=n;this.text=t}return n}();i.messageItem=w;b=function(){function n(n,t){this.message=n;this.elapsedTime=t}return n.prototype.toString=function(){return this.elapsedTime+"> "+this.message},n}();i.traceItem=b;o=function(n){function t(t){n.call(this,"stringResult");this.value=t}return __extends(t,n),t.prototype.toString=function(){return this.value},t}(r);i.stringResult=o;k=function(n){function t(t){n.call(this,"stringArrayResult");this.items=[];this.pageNumber=0;this.pageCount=0;this.items=t.items;this.pageNumber=t.pageNumber;this.pageCount=t.pageCount}return __extends(t,n),t.prototype.toString=function(){return this.items.join("\n")},t}(r);i.stringArrayResult=k;d=function(n){function t(t){if(n.call(this,"hashResult"),this.items=[],t!==undefined&&t!==null)for(var i=0;i<=t.length-1;i++)this.add(t[i].type,t[i].value)}return __extends(t,n),t.prototype.add=function(n,t){this.items.push(new g(n,t))},t}(r);i.hashResult=d;g=function(){function n(n,t){this.type=n;this.value=t}return n}();i.hashItem=g;nt=function(n){function t(t){n.call(this,"ipResult");this.proxy=!1;this.country=null;this.city=null;this.ip=t.ip;this.proxy=t.proxy;this.country=t.country||null;this.city=t.city||null}return __extends(t,n),t}(r);i.ipResult=nt;ut=function(n){function t(){n.apply(this,arguments);this.nameEn=null;this.nameRu=null;this.domain=null;this.domainNational=null;this.fips10=null;this.id=null;this.ioc=null;this.iso3166a2=null;this.iso3166a3=null;this.iso3166num=null;this.itu=null;this.phoneCode=null;this.stanag=null;this.un=null;this.unIso=null}return __extends(t,n),t}(r);i.countryResult=ut;ft=function(n){function t(){n.apply(this,arguments);this.nameEn=null;this.nameRu=null;this.zip=null;this.metroCode=null;this.areaCode=null;this.longitude=null;this.latitude=null}return __extends(t,n),t}(r);i.cityResult=ft;tt=function(n){function t(t){if(n.call(this,"proxyResult"),this.pageNumber=0,this.pageCount=0,this.items=[],this.pageNumber=t.pageNumber,this.pageCount=t.pageCount,t.items!==undefined&&t.items!==null)for(var i=0;i<=t.items.length-1;i++)this.add(t.items[i])}return __extends(t,n),t.prototype.add=function(n){this.items.push(n)},t}(r);i.proxyResult=tt;et=function(){function n(){this.ip="";this.available=0;this.free=0;this.country=null}return n}();i.proxyItem=et;l=function(){function n(){this.value=null;this.url=null;this.errors=0}return n.parse=function(t){if(t===undefined||t===null)return null;var i=new n;if(typeof t=="string")/^[0-9A-Fa-f]{32}$/.test(t)?i.value=t:i.url=t;else if(typeof t=="object"){if(t.value!==undefined&&t.value!==null&&t!=""&&(i.value=t.value),t.url!==undefined&&t.url!==null&&t.url!=""&&(i.url=t.url),t.errors!==undefined&&t.errors!==null&&(i.errors=t.errors),i.value===null&&i.url===null)throw new Error("Token not found.");}else throw new Error("Token value not supported.");return i},n}();i.foxtoolsToken=l;a=function(){function n(){}return n.hit=function(t,i){try{n.counter!==undefined&&n.counter!==null&&n.counter.hit(t,i,null)}catch(r){}},n.init=function(){try{window.Ya===undefined||window.Ya===null?$.getScript("//mc.yandex.ru/metrika/watch.js",function(){n.counter=new window.Ya.Metrika({id:24654338,enableAll:!0})}):(n.counter===undefined||n.counter===null)&&(n.counter=new window.Ya.Metrika({id:24654338,enableAll:!0}))}catch(t){}},n}(),function(n){n[n.auto=0]="auto";n[n.encode=1]="encode";n[n.decode=2]="decode"}(i.dataMode||(i.dataMode={}));st=i.dataMode,function(n){n[n.text=0]="text";n[n.file=1]="file"}(i.outputFormat||(i.outputFormat={}));ht=i.outputFormat,function(n){n[n.None=0]="None";n[n.InternalError=1e3]="InternalError";n[n.NotSupported=1001]="NotSupported";n[n.NotImplemented=1002]="NotImplemented";n[n.UnableToProcessData=1003]="UnableToProcessData";n[n.Timeout=1004]="Timeout";n[n.AccessDenied=1100]="AccessDenied";n[n.AccessTokenError=1110]="AccessTokenError";n[n.AccessTokenNotFound=1111]="AccessTokenNotFound";n[n.NoPermissionToUseTokenForCurrentIp=1112]="NoPermissionToUseTokenForCurrentIp";n[n.AddressIsBlacklisted=1121]="AddressIsBlacklisted";n[n.ArgumentNullOrEmpty=2001]="ArgumentNullOrEmpty";n[n.ArgumentOutOfRange=2002]="ArgumentOutOfRange";n[n.InvalidFormat=3001]="InvalidFormat";n[n.InvalidFileType=3002]="InvalidFileType";n[n.InvalidContentType=3003]="InvalidContentType";n[n.InvalidCast=3004]="InvalidCast";n[n.InvalidValue=3005]="InvalidValue";n[n.DataNotFound=3101]="DataNotFound";n[n.ContentTypeNotFound=3102]="ContentTypeNotFound";n[n.ExternalServiceIsNotAvailable=5e3]="ExternalServiceIsNotAvailable";n[n.ExternalServiceError=5001]="ExternalServiceError"}(i.errorCode||(i.errorCode={}));ot=i.errorCode,function(n){n[n.Any=0]="Any";n[n.Yes=1]="Yes";n[n.No=2]="No"}(i.yesNoAny||(i.yesNoAny={}));ct=i.yesNoAny})(i=n.lib||(n.lib={}));t=function(){function n(){}return n.format=function(n,t){return n===undefined||n===null||n===""?(console.log("Value is empty."),null):(t.length===1&&t[0]!==null&&typeof t[0]=="object"&&(t=t[0]),typeof t=="string"&&(t=[t]),n.replace(/{([^}]*)}/g,function(n,i){return typeof t[i]!="undefined"?t[i]:n}))},n.createCookies=function(n,t,i){var u="",r=new Date;i!==undefined&&i!==null&&(r.setTime(r.getTime()+i*864e5),u="; expires="+r.toUTCString());document.cookie=this.format("{name}={value}{expires}; path=/",{name:n,value:t,expires:u})},n.readCookies=function(n){var r=document.cookie.split(";"),i,t;for(n=n+"=",i=0;i<r.length;i++){for(t=r[i];t.charAt(0)==" ";)t=t.substring(1,t.length);if(t.indexOf(n)==0)return t.substring(n.length,t.length)}return null},n.eraseCookies=function(t){n.createCookies(t,"",-1)},n.isElement=function(n){return n===undefined||n===null?!1:n instanceof HTMLElement},n.isJqueryObject=function(n){return n===undefined||n===null?!1:n instanceof $},n.clinetIsSupportLocalStorage=function(){try{return"localStorage"in window&&window.localStorage!==null}catch(n){return!1}},n.replace=function(n,t,i){return n.replace(new RegExp("("+t+")+","g"),i)},n.htmlEncode=function(n){var i=new RegExp('"+',"g"),t=document.createElement("div"),r=document.createTextNode(n);return t.appendChild(r),t.innerHTML.replace(i,""")},n.htmlDecode=function(n){var t=document.createElement("div");return t.innerHTML=n,t.innerText},n.getQueryStringParameterByName=function(n,t){(t===undefined||t===null)&&(t=location.search);n=n.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var r=new RegExp("[\\?&]"+n+"=([^&#]*)"),i=r.exec(t);return i==null?"":decodeURIComponent(i[1].replace(/\+/g," "))},n.isUrl=function(n){return new RegExp("^(http|https)://([^ \r\n]*)$","i").test(n)},n}();n.utility=t;n.apiForm=r;n.apiRequest=u})(foxtools||(foxtools={}));document.addEventListener?document.addEventListener("DOMContentLoaded",foxtools.lib.client.ready):document.attachEvent&&window.attachEvent("onload",foxtools.lib.client.ready);
//# sourceMappingURL=foxtools.lib.min.js.map