1(function waitForjQuery(attempts){ 2 if (typeof window.jQuery !== "undefined") { 3 4(function($) { 5 6window.gspeechFront = function(options) { 7 8 var $this = this, 9 thisPage = this; 10 11 this.initVars = function() { 12 13 // get options 14 this.options = options; 15 this.is_touch_devise = 'ontouchstart' in window ? true : false; 16 this.options.lazy_load_timeout = 400; 17 18 }; 19 20 this.init = function() { 21 22 this.initVars(); 23 24 this.runFunctions(); 25 }; 26 27 // Start /////////////////////////////////////////////////////////////////////// 28 29 this.runFunctions = function() { 30 31 this.applyCookies(); 32 33 this.applyFunctions(); 34 }; 35 36 this.applyFunctions = function() { 37 38 var $gsp_data_html = $("#gsp_data_html"); 39 40 if (!$gsp_data_html.length) { 41 console.log("GSpeech: required html is missing.") 42 return; 43 } 44 45 var lazy_load = $gsp_data_html.data("lazy_load"); 46 var reload_session = parseInt($gsp_data_html.data("reload_session")); 47 var widget_id = $gsp_data_html.data("w_id"); 48 var v_ind = $gsp_data_html.data("vv_index"); 49 var gt_w = $gsp_data_html.data("gt-w"); 50 51 let storage = { 52 getItem: function() { return null; }, 53 setItem: function() {} 54 }; 55 try { 56 window.localStorage.setItem('test', 'test'); 57 window.localStorage.removeItem('test'); 58 storage = window.localStorage; 59 } catch (e) { 60 try { 61 window.sessionStorage.setItem('test', 'test'); 62 window.sessionStorage.removeItem('test'); 63 storage = window.sessionStorage; 64 } catch (e2) { 65 } 66 } 67 68 let encData = {}; 69 try { 70 var rawEnc = storage.getItem('gsp_enc_data'); 71 if (rawEnc) { 72 encData = JSON.parse(rawEnc) || {}; 73 } 74 } catch (e) { 75 encData = {}; 76 } 77 78 var canAjax = (typeof window.gsp_ajax_obj === 'object') && 79 window.gsp_ajax_obj && 80 typeof gsp_ajax_obj.ajax_url === 'string' && 81 gsp_ajax_obj.ajax_url && 82 typeof gsp_ajax_obj.nonce === 'string' && 83 gsp_ajax_obj.nonce; 84 85 if (reload_session == 1 || !encData.h_enc || !encData.s_enc || !encData.hh_enc) { 86 87 if (canAjax) { 88 jQuery.post(gsp_ajax_obj.ajax_url, { 89 action: 'wpgsp_validate_enc_data', 90 _ajax_nonce: gsp_ajax_obj.nonce 91 }, function(response) { 92 if (response && response.success && response.data) { 93 encData = { 94 s_enc: response.data.s_enc || '', 95 h_enc: response.data.h_enc || '', 96 hh_enc: response.data.hh_enc || '' 97 }; 98 try { storage.setItem('gsp_enc_data', JSON.stringify(encData)); } catch(e){} 99 } 100 loadCloudWidget(encData); 101 }).fail(function() { 102 loadCloudWidget(encData); 103 }); 104 } else { 105 console.warn('[GSpeech] gsp_ajax_obj is missing â loading widget without enc data'); 106 loadCloudWidget(encData); 107 } 108 109 } else { 110 loadCloudWidget(encData); 111 } 112 113 function loadCloudWidget(encData) { 114 var load_timeout = lazy_load == 1 ? thisPage.options.lazy_load_timeout : 0; 115 116 if ($("#gspeech_cloud_widget").length) return; // already loaded 117 118 setTimeout(function () { 119 if ($("#gspeech_cloud_widget").length) return; // double-check 120 $("body").append( 121 '<script id="gspeech_cloud_widget" defer src="https://widget.gspeech.io/' + widget_id + 122 '?v_ind=' + v_ind + '"' + 123 ' data-widget_id="' + widget_id + '"' + 124 ' data-s="' + (encData.s_enc || '') + '"' + 125 ' data-h="' + (encData.h_enc || '') + '"' + 126 ' data-hh="' + (encData.hh_enc || '') + '"' + 127 ' data-gt_w="' + gt_w + '"></script>' 128 ); 129 }, load_timeout); 130 } 131 132 }; 133 134 // Inner methods /////////////////////////////////////////////////////////////////////// 135 136 this.bytesToHex = function(bytes) { 137 138 var hexstring='', h; 139 for(var i=0; i<bytes.length; i++) { 140 h=bytes[i].toString(16); 141 if(h.length==1) { h='0'+h; } 142 hexstring+=h; 143 } 144 return hexstring; 145 }; 146 147 this.applyCookies = function() { 148 149 this.setCookie = function(key, value, expiry) { 150 151 var cookie_val = key + '=' + value + ';path=/'; 152 if(expiry != -1) { 153 var expires = new Date(); 154 expires.setTime(expires.getTime() + (expiry * 60 * 60 * 1000)); // in hours 155 cookie_val += ';expires=' + expires.toUTCString(); 156 } 157 document.cookie = cookie_val; 158 }; 159 160 this.getCookie = function(key) { 161 162 var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); 163 return keyValue ? keyValue[2] : ''; 164 }; 165 166 this.eraseCookie = function(key) { 167 168 var keyValue = this.getCookie(key); 169 this.setCookie(key, keyValue, '-2'); 170 }; 171 }; 172
173 // Call init /////////////////////////////////////////////////////////////////////// 174 175 this.init(); 176}; 177 178$(document).ready(function() { 179 180 // gspeech 3.x 181 var gsp_options = {}; 182 window.gspeech_front = new gspeechFront(gsp_options); 183}); 184 185})(jQuery); 186 187} else if (attempts < 100) { 188 setTimeout(function(){ waitForjQuery(attempts+1); }, 50); 189} else { 190 console.warn("[GSpeech] jQuery not available after waiting."); 191} 192})(0);
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.