-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocator.min.js
1 lines (1 loc) · 3.37 KB
/
locator.min.js
1
const form="undefined"!=typeof global?global:this,baker=function(t,e){"object"==typeof e&&!Array.isArray(e)&&e.init&&(initialized=e.init(form))&&(e=initialized),"function"==typeof define&&(define.amd||define.cmd)?define(function(){return e}):"undefined"!=typeof module&&module.exports?module.exports=e:form[t]=e};baker("locator",{window:null,document:null,acceptedLangs:["en","es","fr","pt","zh-cn","zh-tw"],defaultLang:"en",documentLang:null,browserLang:null,pathLang:null,baseGoogle:null,lang:null,googleTranslator:null,init:function(t){this.window=t,this.document=t.document,this.browserLang=(t.navigator.language||t.navigator.userLanguage).toLowerCase(),this.pathLang=this.document.location.pathname.split("/")[1]||"",this.baseGoogle="/auto/",t.googleTranslateElementInit=this.initGoogleTranslator},translateByQuery:function(t="lang"){this.lang=this.getAccepted(this.getParam(t)),this.translate()},translateByPath:function(){this.lang=this.getAccepted(this.pathLang),this.translate()},getParam:function(t){return(q=this.window.location.search.match(new RegExp(t+"=([^$&]+)")))&&q[1]||!1},insertCss:function(t){var e=this.document.createElement("style");e.type="text/css",e.styleSheet?e.styleSheet.cssText=t:e.innerHTML=t,this.document.getElementsByTagName("head")[0].appendChild(e)},loadJs:function(t,e){var n=this.document.getElementsByTagName("script")[0],a=this.document.createElement("script");return a.src=t,this.document.head.appendChild(a),n.appendChild(a),e&&"function"==typeof e&&(a.onload=e),a},splitLang:function(t){return(t=-1<t.indexOf("-")?t.split("-"):-1<t.indexOf("_")?t.split("_"):[t]).map(t=>t.toLowerCase())},isLang:function(t,e){return!(!t||!e||(t=t.toLowerCase())!=(e=e.toLowerCase())&&0!=t.indexOf(e))},canTranslate:function(t){return t&&!this.isLang(this.documentLang,t)},isAccepted:function(t){return this.acceptedLangs.includes(t)||this.acceptedLangs.includes(this.splitLang(t).slice(0,1)[0])},getAccepted:function(t){return this.acceptedLangs.includes(t)||this.acceptedLangs.includes(t=this.splitLang(t).slice(0,1)[0])?t:this.defaultLang},redirect:function(){this.isAccepted(this.pathLang)||(this.window.location.href=this.getAccepted(this.browserLang)+this.document.location.pathname)},translateTo:function(t=0){var e;t=t||this.lang,this.canTranslate(t)&&(this.document.cookie="googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",this.document.cookie="googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain="+this.document.location.host+";",(e=new Date).setTime(2*e.getTime()),this.document.cookie="googtrans="+this.baseGoogle+t+"; expires="+e.toGMTString()+"; path=/")},translate:function(){this.insertCss(".skiptranslate{display:none!important}.goog-text-highlight{background-color:transparent!important;-webkit-box-shadow:none!important;-moz-box-shadow:none!important;box-shadow:none!important;box-sizing:initial!important;-webkit-box-sizing:initial!important;}font{vertical-align:unset!important}"),this.loadJs("//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit",function(){locator.translateTo()})},initGoogleTranslator:function(){this.locator.canTranslate(this.locator.pathLang)&&(this.locator.googleTranslator=new this.window.google.translate.TranslateElement({pageLanguage:null,layout:this.window.google.translate.TranslateElement.InlineLayout.SIMPLE,autoDisplay:!1},"google_translate_element"),document.body.style="",document.getElementById("goog-gt-tt").remove())}});