MediaWiki:Common.js
Материал из fidoman.ru
Версия от 15:32, 27 января 2022; Sergey (обсуждение | вклад)
Замечание. Возможно, после сохранения вам придётся очистить кэш своего браузера, чтобы увидеть изменения.
- Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl-F5 или Ctrl-R (⌘-R на Mac)
- Google Chrome: Нажмите Ctrl-Shift-R (⌘-Shift-R на Mac)
- Internet Explorer: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl-F5
- Opera: Перейдите в Menu → Настройки (Opera → Настройки на Mac), а затем Безопасность → Очистить историю посещений → Кэшированные изображения и файлы
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */ /// jivo begin function e(e){if(e)return e.src;try{throw new Error("Get script URL")}catch(e){var t=e.stack;if(t){var i=n(t),a=o(t),d=r(t);return i?i[0]:a?a[0]:d?d[0]:null}}}function t(){return document.currentScript?document.currentScript:document.querySelector("script[jv-id]")||document.querySelector("script[data-jv-id]")}function n(e){return e&&e.match(/https?:\/\/(\S+\.com)\/(widget\.js|widget\/[A-Za-z0-9]+)/)}function o(e){return e&&e.match(/^https?:\/\/(\S+)\/script\/widget\/([A-Za-z0-9]+)/)}function r(e){return e&&e.match(/https?:\/\/(\S+)\/script\/geo-widget\/([A-Za-z0-9]+)/)}function i(){var e=window.location&&window.location.protocol;return-1===["http","https"].indexOf(e||"")&&(e="https:"),e}function a(){var n=window.jivo_config&&window.jivo_config.base_url,o=n||e(t());if(!o)return null;var r="main";return["jvs","ru1","sa1","ya","reg","eu1"].forEach((function(e){o&&-1!==o.indexOf(e)&&(r=e)})),r}function d(e,t,n){var o;e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&(e.attachEvent("on"+t,(o=e,function(){n.call(o,window.event)})),e=null)}function s(e){try{d(window,"scroll",e),d(document.body,"mousemove",e)}catch(t){e&&e()}}function l(e,t,n){if(window.removeEventListener)e.removeEventListener(t,n,!1);else{if(!window.detachEvent)return!1;e.detachEvent("on"+t,(function(){n.call(e)}))}}function c(e){try{l(window,"scroll",e),l(document.body,"mousemove",e)}catch(e){console.warn(e)}}function u(){var e=navigator.userAgent.toLowerCase();return-1==e.search(/google/gi)&&-1==e.search(/\+http:\/\/yandex\.com\/bots/gi)&&-1==e.search(/\+http:\/\/www\.cloudflare\.com\/always-online/gi)&&-1==e.search(/linespider\//gi)}function f(e,t,n,o,r){r&&r.error&&(r=r.error),r&&r instanceof Error||(r={}),r.stack=r.stack||"empty",r.message="Bundle init error: "+e+" error.message: "+r.message,r.columnNumber=o,r.lineNumber=n,r.url=t,window.parent.__jivoOnError(r)}var g="loader_loaded",m="no_widget_id_or_confighost",v="error_code_1015",p="widget_deleted",h="ie_loading_blocked";window.__jivoOnError=function(e){if(u())try{var t=a(),n="//err.jivosite.com/widget",o="POST",r={widget:"true",widget_version:window.jivo_version,level:2,url:(s=window.location,s.protocol+"//"+s.host+s.pathname),lineNumber:e&&e.lineNumber,fileName:e&&e.fileName,column:e&&e.columnNumber,full_message:e&&e.stack,short_message:e&&e.message,shard:t},d=new XMLHttpRequest;"withCredentials"in d?d.open(o,i()+n,!0):"undefined"!=typeof XDomainRequest&&(d=new XDomainRequest).open(o,n),d.setRequestHeader("Content-Type","application/json"),d.send(JSON.stringify(r))}catch(e){}var s},function(){var l=.1;window.__hasStorage=!1;try{localStorage.setItem("testLocalStorage","ok"),localStorage.removeItem("testLocalStorage"),window.__hasStorage=!0}catch(e){}function w(l,w,_,b){var y=l.console;if(y||(y={log:function(){},error:function(){}}),function(){if(l.google&&l.google.translate&&0==l.location.href.search(/(http(s?)).+\.translate\.goog/gi))return!1;return!!l.WebSocket}()){if(void 0===l.jivo_magic_var){l.jivo_magic_var=!0;var S,j,C,E,I,L,T,N,O,A,k,B={hasStorage:l.__hasStorage,jivoLoaderVersion:_,loadScript:function(e,t){var n=t||w,o=n.getElementsByTagName("script")[0],r=n.createElement("script");pe(r),o.parentNode.insertBefore(r,o).src=e},currentLoaderVersionCache:b},H=navigator.userAgent.toLowerCase(),x=/iPhone|iPad|iPod|Android|Windows Phone/i.test(H),W=w.createElement("iframe"),R=w.createElement("div"),M=0,q=0,U=0,D=[],J=!1,X=ie(),P=JSON.parse('["AF","CG","CF","GW","ER","IR","IQ","KP","LR","LB","LY","ML","CU","PS","SO","SD","SY","ZW","YE"]')||null,G=JSON.parse('["127-129-12k-12i-12c-12h","12e-12i-12e-124-12c-12h","131-12e-12l-12m-124-12b-12c","124-12g-12o-129-12m-124-12g-12c-12h","127-124-12s-12c-12s","12g-124-12k-12c-12p-12n-124-12h-124","3n-12j-124-12d-12l","12g-129-12o-129-128-12k-12i-12h"]')||null;be("Initialization"),l.__jivoBundleOnLoad=function(e){clearTimeout(I),L=e;var t=((new Date).getTime()-T)/1e3;t>6&&ae("loadTime",t);ae("bundleLoaded",!0),ae("buildNumber",S.build_number),be("Bundle is loaded"),function(){E=w.body.lastChild,R.style&&(R.style.opacity="0",R.style.visibility="hidden",R.style.width=0,R.style.height=0,R.style.overflow="hidden");R.setAttribute("id","jivo-iframe-container"),R.appendChild(W),E?E.parentNode.insertBefore(R,E.nextSibling):w.body.appendChild(R);re()}()},l.__jivoBundleInit=function(e){e.loaderContext=B,function(){L=null;var e=function(e){if(e){var t=e.querySelectorAll&&e.querySelectorAll(".js-jivo-bundle");return t&&t.length>0?t:e.getElementsByClassName("js-jivo-bundle")}}(ye());if(!e)throw y.error("Cannot get bundle script element"),new Error("Cannot get bundle script element");for(var t=0;t<e.length;t++)e[t].parentNode&&e[t].parentNode.removeChild(e[t]);e=null}()},l.jivo_init=function(){M=0;var e=w.createEvent("Event");e.initEvent("jBeforeunload",!0,!0),l.dispatchEvent(e),ne()},l.jivo_destroy=function(){M=0;var e=w.createEvent("Event");e.initEvent("jBeforeunload",!0,!0),l.dispatchEvent(e),delete l.jivo_magic_var,setTimeout((function(){R.parentNode.removeChild(R)}),10)},B.getHostURL=_e,B.store=X,B.setInStore=ae;var z,V=!1,F=function(e){try{e.blockedURI&&-1!==e.blockedURI.indexOf("jivosite")&&(V=!0,w.removeEventListener("securitypolicyviolation",F))}catch(e){}}.bind(this);try{d(w,"securitypolicyviolation",F)}catch(e){}ce(),!(!(z=O)||!/^\d+$/.test(z)&&10!=z.length)||(O=null,N=null,y.error("Widget id is not valid.")),K(g,5),function(){(X=ie()).geoWidgetInfo.widgetId&&(O=X.geoWidgetInfo.widgetId,X=ie(),N=X.configHost);ae("isNewCode",J),B.store=X}();var Z=null;A&&(k=A.getAttribute("nonce"))&&(l.jivo_cspNonce=k),O&&N?(be("widgetId:",O,"configHost:",N),Y(le())):O&&N||(K(m,5),y.error("Failed to evaluate the widgetId or configHost"))}}else y.log("Not supported browser");function Y(e,t){if(D.push(e),++U>4){be("Config load limit is exceeded"),B.hasStorage&&localStorage.removeItem("jv_loader_info_"+O);var n=new Error("Config load limit is exceeded"),o="Config urls: "+D.join(";\r\n");try{n.stack=o}catch(e){n=new Error("Config load limit is exceeded. "+o)}l.__jivoOnError(n)}else if(be("Loading config from",e),X.deletedInfo.widgetId&&X.deletedInfo.widgetId===O&&X.deletedInfo.resolveTime&&parseInt(X.deletedInfo.resolveTime)>=(new Date).getTime())y.error("This widget is permanently removed");else{var r=new XMLHttpRequest;r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status){var e=Ee(he(r));e?(be("Config is loaded",e),e.isDeleted?ge():t?(e.chat_mode=t.chat_mode,e.options=t.options,e.botmode=t.botmode,e.geoip=t.geoip,e.maintenance=!!t.maintenance,Q(e,null)):function(e,t){var n=new XMLHttpRequest;function o(){return!1}n.onreadystatechange=function(){if(4===n.readyState)if(200===n.status){var o=Ee(he(n));if(!o)throw new Error("Load widget status error");var r=n.getResponseHeader("X-BotMode"),i=n.getResponseHeader("X-GeoIP"),a=o.agents&&o.agents.length;be("Status is loaded",o,r,i,a),e.lastStatus=o,e.botmode="yes"===r?"yes":null,e.geoip=i||";;;",e.chat_mode=a?"online":"offline",e.options=o.premium?888:0,o.bots&&o.bots.length&&(e.bots=o.bots),e.maintenance=!!o.maintenance,t(o.config_updated_ts)}else if(0!==n.status)throw e.botmode=null,e.geoip=";;;",e.chat_mode="offline",e.options=0,t(null),480==n.status&&be("Site is under maintenance, try again later."),new Error("Load widget status error: "+n.status)};var r="/configs/development/status.json",a=o()?r:i()+"//"+e.comet.host+"/widget/status/"+e.site_id+"/"+e.widget_id+"?rnd="+Math.random();n.open("GET",a,!0),n.send(null)}(e,(function(t){Q(e,t)}))):me(!0)}else 0!==r.status&&me()},r.open("GET",e,!0),r.send(null)}}function $(e){var t={event:e,widget_id:O,t:(new Date).getTime(),param1:"52.9.0",shard:a()};if(u())try{var n=i()+!0?"//telemetry.jivosite.com/w?cb=loader":"//telemetry.dev.jivosite.com:2443/w";for(var o in t)n+="&"+o+"="+encodeURIComponent(t[o]);var r=new XMLHttpRequest;"withCredentials"in r?r.open("GET",n,!0):"undefined"!=typeof XDomainRequest&&(r=new XDomainRequest).open("GET",n),r.send()}catch(e){}}function K(e,t){Math.random()<=.01*t&&$(e)}function Q(e,t){if(be("checkConfig",e.config_updated_ts,t),e.isDeleted)ge();else if(function(){var e=navigator.userAgent.toLowerCase();return-1!==e.indexOf("msie")||-1!==e.indexOf("trident")}()&&e.disable_widget_on_ie11)$(h);else{if(t&&e.config_updated_ts&&e.config_updated_ts!=t)return be("update configUpdatedTs in store",t),ae("configUpdatedTs",t),Y(le(),e);if(e.regions&&!X.isChatStarted){var n=function(e){var t,n,o=e.regions,r=fe(e.geoip);if(o){for(var i=Object.keys(o),a=0;a<i.length;a++)for(var d=o[i[a]],s=0;s<d.length;s++)if(1!=d.length||"default"!==d[s]){var l=fe(d[s]);if(r.country===l.country){if(r.region===l.region)return ue(i[a],d[s],e.geoip);n||l.region||(n=ue(i[a],d[s],e.geoip))}}else t=i[a];if(n)return n;if(t)return ue(t,"default",e.geoip)}}(e);if(n.widgetId!==O)return be("Wrong geo-widget widgetId",O),ae("geoWidgetInfo",n),O=n.widgetId,void Y(le())}if((Z=e.ab_segment)&&Z.name&&Z.host&&Z.staticHost&&1!==e.site_id)if(be("AB-testing segmentation is enabled in config"),function(e,t){var n=X.abTesting,o=!1;o=n&&n.name===e.name?n.match:function(e,t){if(be('Check for criteria match of test "'+e.name+'"'),e.device){if(!function(e){if("desktop"===e)return je()&&!Ce();if("mobile"===e)return Ce();if("all"===e)return je()||Ce();return!1}(e.device))return be('Segment "'+e.name+'" is NOT matched. Criteria: device'),!1}if(e.locale){if(!(e.locale===t.locale))return be('Segment "'+e.name+'" is NOT matched. Criteria: locale'),!1}if(e.percentage){if(!(n=e.percentage,Math.random()<=.01*n))return be('Segment "'+e.name+'" is NOT matched. Criteria: percentage'),!1}var n;return be('Segment "'+e.name+'" is matched!'),!0}(e,t);return ae("abTesting",{name:e.name,match:o}),o}(Z,e)){be("Ab-testing segment match! Segment:",Z.name);var o="//"+Z.host;be('Setting new base_url. Was: "'+e.base_url+'". New: "'+o+'".'),e.base_url=o}else be("Ab-testing segment is NOT matched");else ae("abTesting",null),be("AB-testing segmentation is NOT enabled in config"),ae("configHost",N);!function(e){if(ae("log",!!e.logs),l.jivo_config=S=e,function(){if(S.host_blacklist)for(var e=S.host_blacklist.split(","),t=0;t<e.length;t++)if(l.location.host.indexOf(e[t].replace(" ",""))>=0)return!0;return!1}())throw be("Host is blacklisted",l.location.host),new Error("Placing widget is forbidden on "+l.top.location.host);if(t=S.geoip.split(";")[0],P.indexOf(t)>=0)return y.log("[Jivo]: Service unavailable for country");if(!e.disable_stop_words&&function(){var e=!1,t=(d=G,d.map((function(e){return e.split("-").map((function(e){return String.fromCharCode(parseInt(e,32)-20)})).join("")}))),n=w.querySelector('meta[name="description"]'),o=w.querySelector('meta[name="keywords"]'),r=w.title,i=n&&n.content?n.content:"",a=o&&o.content?o.content:"";var d;(we(r,t)||we(i,t)||we(a,t))&&(e=!0);return e}())return $(v),void be("Init error, code 1015.");if(x&&S.disable_mobile)return void be("Mobile widget is disabled");var t;"complete"==w.readyState?ee():X.bundleLoaded&&X.buildNumber==S.build_number?"interactive"==w.readyState?ee():d(l,"DOMContentLoaded",ee):(ae("bundleLoaded",!1),d(l,"load",ee))}(e)}}function ee(){be("Widget initialization"),function(){be("Iframe initialization"),W.src="javascript:void(0)",W.role="presentation",W.allow="autoplay",W.title="Jivochat",W.setAttribute("name","jivo_container"),W.setAttribute("id","jivo_container"),W.setAttribute("frameborder","no"),k&&W.setAttribute("nonce",k);l.atob&&"complete"!==w.readyState?d(l,"load",ne):ne();d(l,"message",(function(e){if(e&&e.data&&"object"==typeof e.data){var t=e.data;"in_node_webkit"==t.name&&(l.jivo_cobrowse={source:e.source,origin:e.origin}),"iframe_url_changed"!=t.name&&"iframe_url_changed"!=t||re()}else S&&1===S.logs&&y&&y.log&&y.log("Error receive postMessage, window message event is empty.")}))}()}function te(){var e=_e();be("loadBundleAfterWait",e,B),c(te),oe(e)}function ne(){var e=_e();if(!B.store.isChatStarted&&S.enable_bundle_wait){be("addWaitActions");try{s(te),setTimeout((function(){be("5s load",B.store),l.jivo_api||te()}),5e3)}catch(t){oe(e)}}else be("startLoadBundle",e),oe(e)}function oe(e){be("Insertion of bundle code from",e);var t=ye(),n=w.createElement("script"),o=function(e){var t=S.bundle_folder?S.bundle_folder:"";return e+t+"/js/bundle_"+S.locale+".js?rand="+S.build_number}(e);T=(new Date).getTime(),pe(n),n.className="js-jivo-bundle",n.src=i()+o,B.bundleSrc=o,n.onerror=function(){be("loadBundle errorBundle",e),w.getElementById("jcont")&&function(e,t,n){if(clearTimeout(I),++q>=5){if(be("Bundle load retries count is exceeded"),be("Bad csp is: "+V),V)return void y.error("Widget not loaded due CSP security policy.");var o=new Error("Bundle NOT loaded. Type: "+e+(t?". Host: "+t:"")+(n?". Status code: "+n:""));return void l.__jivoOnError(o)}ne()}("errorBundle",e)},t.appendChild(n)}function re(){if(!(M++>3)){if(!L)return M--,ne();try{C=W.contentWindow.document}catch(e){j=w.domain,W.src="javascript:var d=document.open();d.domain='"+j+"';void(0);",C=W.contentWindow.document}var e='<meta name="google" content="notranslate"><meta http-equiv="X-UA-Compatible" content="IE=edge" />',t="";try{t="window.onerror = "+f.toString()+";"}catch(e){}var n=(S&&!S.disable_error_reporting?t:"")+L;if(!(navigator.userAgent.toLowerCase().indexOf("firefox")>-1)&&C.head&&C.body){C.body.class="notranslate",C.head.innerHTML=e;var o=w.createElement("script");o.type="text/javascript",k&&o.setAttribute("nonce",k),o.innerHTML=n,C.head.appendChild(o)}else{var r='<body class="notranslate"></body>',i='<script type="text/javascript"'+(k?'nonce="'+k+'"':"")+">"+n+"<\/script>",a="<head>"+e+i+"</head>";C.write("<!doctype HTML>"+a+r),i=null,r=null,a=null}C.close(),n=null}}function ie(){var e={isChatStarted:null,geoWidgetInfo:{widgetId:null,clientLocation:null,region:null},configHost:null,deletedInfo:{widgetId:null,resolveTime:null},abTesting:null,buildNumber:null,bundleLoaded:null,isNewCode:null,loadTime:null,log:null,configUpdatedTs:null};if(B.hasStorage&&(localStorage.removeItem("jv_loader_info"),O)){var t=Ee(localStorage.getItem("jv_loader_info_"+O));t&&de(t,e)}return e}function ae(e,t){if(X[e]=t,B.hasStorage&&O){var n={};de(X,n),localStorage.setItem("jv_loader_info_"+O,(o=n,l.MooTools&&void 0===JSON.stringify?JSON.encode(o):JSON.stringify(o)))}var o}function de(e,t){Object.keys(e).forEach((function(n){(function(e){if(se(e))return!0;if("object"==typeof e){for(var t=Object.keys(e),n=0;n<t.length;n++)if(!se(e[t[n]]))return!1;return!0}})(e[n])||(t[n]=e[n])}))}function se(e){return null===e&&"object"==typeof e}function le(){var e="";return be("getConfigUrl",X.configUpdatedTs),X.configUpdatedTs&&(e="?v="+X.configUpdatedTs),i()+N+"/script/widget/config/"+O+e}function ce(){var i=e(A=t());if(i&&i.match(/</))be("Invalid codeHost",i);else{var a,d=n(i),s=o(i),l=r(i);N||(d?(N="//"+d[1],J=!0):s?N="//"+s[1]:l&&(N="//"+l[1])),O||(s&&s[2]?(O=s[2],J=!1):l&&l[2]?(O=l[2],J=!1):(J=!0,A&&(O=A.getAttribute("jv-id")||A.getAttribute("data-jv-id")),O||(a=i&&i.match(/https?:\/\/\S+\/widget\/([A-Za-z0-9]+)/),O=a?a[1]:null))),be("getWidgetIdAndConfigHost",O,N)}}function ue(e,t,n){return{widgetId:e,region:t,clientLocation:n}}function fe(e){if("string"==typeof e&&""!==e){var t=e.split(";");return{country:t[0],region:t[1],city:t[2]}}}function ge(){be("Widget was removed",O),ae("configHost",null),X.geoWidgetInfo.widgetId||X.isChatStarted?(ae("geoWidgetInfo",ue(null,null,null)),ae("isChatStarted",null),ve()):(ae("deletedInfo",{widgetId:O,resolveTime:((new Date).getTime()+6048e5).toString()}),y.error("Widget "+O+" is permanently removed. Host: "+N),$(p))}function me(e){be("Config loading error:",e?"parse":"request"),ae("geoWidgetInfo",ue(null,null,null)),ae("isChatStarted",null),ae("configHost",null),e||ve()}function ve(){O=null,N=null,ce(),Y(le())}function pe(e){if(e)return e.type="text/javascript",e.async=!0,e.charset="UTF-8",k&&e.setAttribute("nonce",k),e}function he(e){return e.responseType&&"text"!==e.responseType?"document"===e.responseType?e.responseXML:e.response:e.responseText}function we(e,t){for(var n=!1,o=0;o<t.length;o++){var r=t[o].toLowerCase(),i=new RegExp("([, .]|^)"+r+"([, .]|$)","gi");if(e.toLowerCase().search(i)>-1){n=!0;break}}return n}function _e(){return S.base_url}function be(){if(X.log){var e=Array.prototype.slice.call(arguments||[]);e.unshift("Loader:"),y.log.apply(y,e)}}function ye(){var e=w.head||w.getElementsByTagName("head")[0];if(!e)throw y.error("Cannot get document head element"),new Error("Cannot get document head element");return e}function Se(e){return-1!==H.indexOf(e)}function je(){return Se("chrome")&&!Se("opr/")&&"Google Inc."===l.navigator.vendor}function Ce(){return!Se("windows")&&Se("android")}function Ee(e){try{return l.MooTools&&void 0===JSON.parse?JSON.decode(e):JSON.parse(e)}catch(e){return e.message="Config parse error: "+O+"\n\n"+e.message,l.__jivoOnError(e),null}}}var _=w,b=null;if(window.__hasStorage){try{b=JSON.parse(localStorage.getItem("__jivoLoader"))}catch(e){jivoLog("Loader cache parse error.")}b&&b.version>l&&(_=new Function("window","document","broswerCacheLoaderVersion","currentLoaderVersionCache","("+b.code+")(window, document, broswerCacheLoaderVersion, currentLoaderVersionCache)"))}try{_(window,document,l,b?b.version:l)}catch(e){e.message=e.message?"Loader error. "+e.message:"Loader error",window.__jivoOnError(e),delete window.jivo_magic_var,(_=w)(window,document,l,l)}}(); /// jivo end