https://www.soundcu.com/wp-content/plugins/pixelspoke-translatepre…/ps-tp-auto-switcher.js?ver=1.2.0
1var ps_tp_auto_switcher = { 2 toggleEl: document.querySelectorAll('.ps_lang_switcher'), 3 bodyEl: document.querySelector('body'), 4 sanitize: function(string) { 5 return ( string ? string.replace('-', '_').replace(/[^\w_]/g,'') : '' ) 6 }, 7 chooseLang: function(langCode) { 8 window.localStorage.setItem("chooseLang", langCode); 9 }, 10 getChosenLangCode: function() { 11 var that = this; 12 return that.sanitize(window.localStorage.getItem("chooseLang")); 13 }, 14 getBrowserLang: function() { 15 var that = this; 16 return that.sanitize(window.navigator.language); 17 }, 18 getCurrentLang: function() { 19 var that = this; 20 var tpClasses = Array.from(that.bodyEl.classList).filter(cl => cl.startsWith('translatepress-')); 21 return ( tpClasses.length > 0 ? tpClasses[0].replace('translatepress-', '') : false ) 22 23 }, 24 getTargetLang: function() { 25 var that = this; 26 return ( that.toggleEl.length > 0 ? that.sanitize(that.toggleEl[0].dataset.targetlangcode) : false); 27 }, 28 init: function() { 29 var that = this; 30 that.toggleEl.forEach(function(el) { 31 el.addEventListener('click', function() { 32 that.chooseLang(that.sanitize(el.dataset.targetlangcode)); 33 }); 34 }); 35 var chosen = that.getChosenLangCode(); 36 if ( chosen ) { 37 // if chosen language is not current language switch to it 38 } else { 39 // if there is no chosen language 40 // and the browser language is different form the current language 41 // and the target language IS the same as the browser 42 // switch 43 var browser = that.getBrowserLang(); 44 var current = that.getCurrentLang(); 45 var target = that.getTargetLang(); 46 if ( browser != current && browser == target ) { 47 // switcch to the browser version!! 48 window.location = that.toggleEl[0].href 49 } 50 } 51 } 52} 53ps_tp_auto_switcher.init();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.