﻿"use strict";function post(n,t,i,r,u){xhr=new XMLHttpRequest;xhr.processData=!1;xhr.cache=!1;xhr.timeout=6e6;xhr.onreadystatechange=r;xhr.onerror=u;xhr.withCredentials=!0;xhr.open("POST",baseUrl+n,!0);i&&xhr.setRequestHeader("Content-Type","application/json; charset=utf-8");xhr.send(t);gaEvent("start",jobName)}function workProcess(){setTimeout(function(){executeStatusQuery()},5e3)}function workSuccess(n){n.status==="completed"?(showProcessing(!1),taskId="",loading=!1,gaEvent("completed",jobName)):n.status==="pending"?(showProcessing(!0),n.id!==undefined&&(taskId=n.id),workProcess()):n.status==="faulted"?(showProcessing(!1),taskId="",showAlert(!0,n.statusMessage),loading=!1,gaEvent("faulted",jobName)):(showProcessing(!1),taskId="",loading=!1,gaEvent("error_unknown",jobName),showAlert(!0,"Unknown error."))}function executeStatusQuery(){if(taskId===undefined||taskId===""){showProcessing(!1);showAlert(!0,"Server is busy, try later");loading=!1;return}xhr=new XMLHttpRequest;xhr.processData=!1;xhr.cache=!1;xhr.contentType=!1;xhr.timeout=12e4;xhr.onreadystatechange=onreadystatus;xhr.onerror=onerr;xhr.open("GET",baseUrl+jobName+"?id="+taskId,!0);xhr.send()}function canDo(){return isCanDoUrl()||isCanDoText()||isCanFiles()}function isCanDoUrl(){return!!url&&!loading&&IsValid(url)}function isCanDoText(){return!!sourceText&&!loading}function isCanFiles(){return!!selectedFiles&&!loading&&checkLessMaxSize()}function IsValid(n){var t=RegExp(_urlRegexWithHTTP,"i");return t.test(n)}function checkLessMaxSize(){var i=2097152,n=!1,t=0;return Array.from(selectedFiles.keys()).length>0&&(selectedFiles.forEach(function(n){n.size<i&&t++}),t===Array.from(selectedFiles.keys()).length&&(n=!0)),n}function isProtocolWithUrl(n){for(var i=!1,t=0;t<protocols.length;t++)if(n.startsWith(protocols[t])){i=!0;break}return i}function AddHttpsProtocolToUrl(n){return"https://"+n}function showProcessing(n){var t=byid("loader");n&&!t.classList.contains(ac)?t.classList.add(ac):!n&&t.classList.contains(ac)&&t.classList.remove(ac)}function showAlert(n,t){var i=byid("status");n&&!i.classList.contains(ac)?(i.textContent=t,i.classList.add(ac)):!n&&i.classList.contains(ac)&&(i.textContent="",i.classList.remove(ac))}function byid(n){return document.getElementById(n)}function gaEvent(n,t){t||(t="Social");var i={eventCategory:t,eventAction:n};if(typeof gtag=="undefined")console.info("[LOG] Google Analytics is off. Tried to send event:",i);else try{gtag("event",t,i)}catch(r){console.info("[ERROR] Error while sending event to Google Analytics:",i)}}var _urlRegexWithHTTP="^(?!mailto:)(?:(?:http|https|ftp)://)?(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$",protocols=["http","https"],loading=!1,xhr=new XMLHttpRequest,selectedFiles=null,url="",sourceText="",ac="active",hide="hidden",taskId="",jobName="",onerr=function(n){console.log(n);loading=!1;showAlert(!0,"Service temporary unavailable.");showProcessing(!1);gaEvent("error_api",jobName)};