1(function(){ 2 3 String.prototype.capitalize = function () { 4 return this.charAt(0).toUpperCase() + this.slice(1) 5 }; 6 7 function fetchJSONFile(path, callback, error) { 8 var httpRequest = new XMLHttpRequest(); 9 httpRequest.onreadystatechange = function() { 10 if (httpRequest.readyState === 4) { 11 if (httpRequest.status === 200) { 12 13 if(httpRequest.responseText){ 14 var data = JSON.parse(httpRequest.responseText); 15 callback(data); 16 } 17 18 } else { 19 error(); 20 } 21 } 22 }; 23 httpRequest.open('GET', path); 24 httpRequest.send(); 25 } 26 27 28 function formatTemp(temp, units){ 29 if(units == 'c'){ 30 return Math.round(temp) + 'º'; 31 }else{ 32 return Math.round((temp * 1.8) + 32) + 'º'; 33 } 34 } 35 36 function formatSpeed(speed,units){ 37 if(units == 'c'){ 38 return Math.round(speed) + ' km/h' 39 }else{ 40 return Math.round(speed * 0.62137) + ' mph' 41 } 42 } 43 44 function formatVol(vol,units){ 45 if(units == 'c'){ 46 return parseFloat(vol).toFixed(2) + ' mm' 47 }else{ 48 return parseFloat((vol / 25.4).toFixed(2)) + ' in' 49 } 50 } 51 52 function tConvert (time) { 53 54 time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time]; 55 56 if (time.length > 1) { 57 time = time.slice (1); 58 time[5] = +time[0] < 12 ? ' AM' : ' PM'; 59 time[0] = +time[0] % 12 || 12; 60 } 61 return time.join (''); 62 } 63 64 65 let WIYCW_widgets = document.querySelectorAll(".WIYCW-wrapper") 66 67 68 WIYCW_widgets.forEach(widget =>{ 69 70 71 72 let content = widget.querySelectorAll(".WIYCW-content")[0] 73 74 widget.style.color = widget.dataset.textcolor 75 widget.style.backgroundColor = widget.dataset.backgroundcolor 76 widget.style.border = "1px solid " + widget.dataset.bordercolor 77 78 let iconsShadowClass = widget.dataset.shadow == "on" ? '-shadow' : '' 79 80 let iconsColorClass = widget.dataset.iconscolor == "dark" ? 'WIYCW-icon-dark' : 'WIYCW-icon-light' 81 iconsColorClass += iconsShadowClass 82 let iconsColorPath = widget.dataset.weathericonscolor == "color" ? 'color' : 'monocromatic' 83 84 let weatherIconsColorClass = 'WIYCW-icon-color' 85 switch(widget.dataset.weathericonscolor){ 86 case "color": 87 weatherIconsColorClass = 'WIYCW-icon-color' + iconsShadowClass 88 break; 89 case "dark": 90 weatherIconsColorClass = 'WIYCW-icon-dark' + iconsShadowClass 91 break; 92 case "light": 93 weatherIconsColorClass = 'WIYCW-icon-light' + iconsShadowClass 94 break; 95 default: 96 weatherIconsColorClass = 'WIYCW-icon-color' + iconsShadowClass 97 break; 98 } 99 100 let r = "" 101 try{ 102 r = window.btoa(window.location.hostname) 103 }catch(er){} 104 105 106 107 function getWeatherData(url, error){ 108 fetchJSONFile(url, function(data){ 109 110 if(data.error){ 111 console.log(data.message) 112 error(); 113 return 114 } 115 content.innerHTML = "" 116 117 if(widget.dataset.today == "on"){ 118 const now = document.createElement("div"); 119 now.classList = "WIYCW-now" 120 121 const now_row1 = document.createElement("div"); 122 now_row1.classList = "WIYCW-now-row1" 123 124 if(widget.dataset.nowicon == "on"){ 125 const icon = document.createElement("div"); 126 icon.classList = "WIYCW-now-icon" 127 128 const img = document.createElement("img"); 129 img.src = widget.dataset.path + "/resources/icons/weather-icons/"+iconsColorPath + '/' + data.now.icon + ".svg" 130 img.alt = 'Current weather' 131 img.style.width = "70px" 132 img.style.height = "70px" 133 img.classList = weatherIconsColorClass 134 icon.appendChild(img) 135 now_row1.appendChild(icon) 136 } 137
138 if(widget.dataset.nowtemp == "on"){ 139 const temp = document.createElement("div"); 140 temp.innerHTML = formatTemp(data.now.temp, widget.dataset.units) 141 temp.classList = "WIYCW-now-temp" 142 now_row1.appendChild(temp) 143 } 144 145 if(widget.dataset.nowicon == "off" && widget.dataset.nowtemp == "off"){ 146 now_row1.style.display = "none" 147 } 148 149 const now_row_info = document.createElement("div"); 150 now_row_info.classList = "WIYCW-now-row-info" 151 152 153 if(widget.dataset.nowsunrise == "on"){ 154 const sunriseIcon = document.createElement("img"); 155 sunriseIcon.alt = 'Sunrise' 156 sunriseIcon.classList = "WIYCW-item-icon " + iconsColorClass 157 sunriseIcon.src = widget.dataset.path + "/resources/icons/ui-icons/sunrise.svg" 158 sunriseIcon.style.width = "11px" 159 sunriseIcon.style.height = "11px" 160 161 const sunrise = document.createElement("div"); 162 sunrise.classList = "WIYCW-now-row-info-col" 163 164 sunrise.appendChild(sunriseIcon) 165 166 if(widget.dataset.timeformat === 'standard'){ 167 data.now.sunrise = tConvert(data.now.sunrise); 168 } 169 170 sunrise.innerHTML += data.now.sunrise 171 now_row_info.appendChild(sunrise) 172 173 const sunsetIcon = document.createElement("img"); 174 sunsetIcon.alt = 'Sunset' 175 sunsetIcon.classList = "WIYCW-item-icon " + iconsColorClass 176 sunsetIcon.src = widget.dataset.path + "/resources/icons/ui-icons/sunset.svg" 177 sunsetIcon.style.width = "11px" 178 sunsetIcon.style.height = "11px" 179 180 const sunset = document.createElement("div"); 181 sunset.classList = "WIYCW-now-row-info-col" 182 183 if(widget.dataset.timeformat === 'standard'){ 184 data.now.sunset = tConvert(data.now.sunset); 185 } 186 187 sunset.appendChild(sunsetIcon) 188 sunset.innerHTML += data.now.sunset 189 now_row_info.appendChild(sunset) 190 } 191 192 if(widget.dataset.nowhumidity == "on"){ 193 194 const dropIcon = document.createElement("img"); 195 dropIcon.alt = 'Humidity'; 196 dropIcon.classList = "WIYCW-item-icon " + iconsColorClass 197 dropIcon.src = widget.dataset.path + "/resources/icons/ui-icons/dew-point.svg" 198 dropIcon.style.width = "11px" 199 dropIcon.style.height = "11px" 200 201 const humidity = document.createElement("div"); 202 humidity.classList = "WIYCW-now-row-info-col" 203 204 humidity.appendChild(dropIcon) 205 humidity.innerHTML += data.now.humidity + "%" 206 now_row_info.appendChild(humidity) 207 } 208 209 if(widget.dataset.nowwind == "on"){ 210 211 const windRotation = document.createElement("div"); 212 windRotation.classList = "WIYCW-item-icon " + iconsColorClass 213 windRotation.style.width = "11px" 214 windRotation.style.height = "11px" 215 windRotation.style.display = "flex" 216 217 const arrowIcon = document.createElement("img"); 218 arrowIcon.alt = 'Wind direction'; 219 arrowIcon.src = widget.dataset.path + "/resources/icons/ui-icons/arrow.svg" 220 arrowIcon.style.width = "11px" 221 arrowIcon.style.height = "11px" 222 arrowIcon.style.transform = "rotate("+data.now.wind_deg+"deg)" 223 224 windRotation.appendChild(arrowIcon) 225 226 const wind = document.createElement("div"); 227 wind.classList = "WIYCW-now-row-info-col" 228 229 wind.appendChild(windRotation) 230 wind.innerHTML += formatSpeed(data.now.wind_speed, widget.dataset.units) 231 now_row_info.appendChild(wind) 232 233 } 234 235 if(widget.dataset.nowpressure == "on"){ 236 237 const pressureIcon = document.createElement("img"); 238 pressureIcon.alt = 'Pressure' 239 pressureIcon.classList = "WIYCW-item-icon " + iconsColorClass 240 pressureIcon.src = widget.dataset.path + "/resources/icons/ui-icons/pressure.svg" 241 pressureIcon.style.width = "11px" 242 pressureIcon.style.height = "11px" 243 244 const pressure = document.createElement("div"); 245 pressure.classList = "WIYCW-now-row-info-col" 246 247 pressure.appendChild(pressureIcon) 248 pressure.innerHTML += data.now.pressure + " hPa" 249 now_row_info.appendChild(pressure) 250 } 251 252 if(widget.dataset.nowcloudiness == "on"){ 253 254 const cloudinessIcon = document.createElement("img"); 255 cloudinessIcon.alt = 'Cloudiness' 256 cloudinessIcon.classList = "WIYCW-item-icon " + iconsColorClass 257 cloudinessIcon.src = widget.dataset.path + "/resources/icons/ui-icons/clouds.svg" 258 cloudinessIcon.style.width = "11px" 259 cloudinessIcon.style.height = "11px" 260 261 const cloudiness = document.createElement("div"); 262 cloudiness.classList = "WIYCW-now-row-info-col" 263 264 cloudiness.appendChild(cloudinessIcon) 265 cloudiness.innerHTML += data.now.cloudiness + "%" 266 now_row_info.appendChild(cloudiness) 267 } 268 269 270 now.appendChild(now_row1) 271 now.appendChild(now_row_info) 272 content.appendChild(now) 273 274 } 275 276 277 278 if(widget.dataset.days !== "off"){ 279 const forecast = document.createElement("div"); 280 forecast.classList = "WIYCW-forecast WIYCW-forecast-"+widget.dataset.layout 281 let number = 0; 282 for(const day of data.forecast){ 283 284 number ++ 285 286 if(number > widget.dataset.days){ 287 break 288 }
289 const row = document.createElement("div"); 290 row.classList = "WIYCW-forecast-row" 291 const date = document.createElement("div"); 292 293 if(number == 1){ 294 date.innerHTML = WIYCW_i18n['today'].capitalize() 295 }else if(number == 2){ 296 date.innerHTML = WIYCW_i18n['tomorrow'].capitalize() 297 }else{ 298 date.innerHTML = (WIYCW_i18n['week_days'][day.wday]).capitalize() + " " + day.day 299 } 300 301 date.classList = "WIYCW-forecast-date WIYCW-col-1" 302 row.appendChild(date) 303 304 if(widget.dataset.temp == "on"){ 305 const temp = document.createElement("div"); 306 temp.classList = "WIYCW-forecast-temp WIYCW-col-1" 307 temp.innerHTML = formatTemp(day.temp_max, widget.dataset.units) + " / " + formatTemp(day.temp_min, widget.dataset.units) 308 row.appendChild(temp) 309 } 310 311 if(widget.dataset.forecasticon == "on"){ 312 const icon = document.createElement("div"); 313 icon.classList = "WIYCW-forecast-icon WIYCW-col-1" 314 const img = document.createElement("img"); 315 img.alt = 'Forecast' 316 img.src = widget.dataset.path + "/resources/icons/weather-icons/"+ iconsColorPath + '/'+ day.icon + ".svg" 317 img.style.width = "30px" 318 img.style.height = "30px" 319 img.classList = weatherIconsColorClass 320 icon.appendChild(img) 321 row.appendChild(icon) 322 323 } 324 325 if(widget.dataset.rainchance == "on"){ 326 327 const umbrellaIcon = document.createElement("img"); 328 umbrellaIcon.alt = 'Rain chance' 329 umbrellaIcon.classList = "WIYCW-item-icon " + iconsColorClass 330 umbrellaIcon.src = widget.dataset.path + "/resources/icons/ui-icons/umbrella.svg" 331 umbrellaIcon.style.width = "11px" 332 umbrellaIcon.style.height = "11px" 333 334 const pop = document.createElement("div"); 335 pop.appendChild(umbrellaIcon) 336 pop.classList = "WIYCW-forecast-pop WIYCW-col-1" 337 pop.innerHTML += Math.round(day.pop*100) + "%" 338 row.appendChild(pop) 339 } 340 341 if(widget.dataset.rain == "on"){ 342 const rain = document.createElement("div"); 343 rain.classList = "WIYCW-forecast-rain WIYCW-col-1" 344 rain.innerHTML = formatVol(day.rain, widget.dataset.units) 345 row.appendChild(rain) 346 } 347 348 if(widget.dataset.wind == "on"){ 349 350 const windRotation = document.createElement("div"); 351 windRotation.classList = "WIYCW-item-icon " + iconsColorClass 352 windRotation.style.width = "11px" 353 windRotation.style.height = "11px" 354 windRotation.style.display = "flex" 355 356 357 const arrowIcon = document.createElement("img"); 358 arrowIcon.alt = 'Wind direction' 359 arrowIcon.src = widget.dataset.path + "/resources/icons/ui-icons/arrow.svg" 360 arrowIcon.style.width = "11px" 361 arrowIcon.style.height = "11px" 362 arrowIcon.style.transform = "rotate("+day.wind_deg+"deg)" 363 364 windRotation.appendChild(arrowIcon) 365 366 const wind = document.createElement("div"); 367 wind.classList = "WIYCW-forecast-wind WIYCW-col-1" 368 369 wind.appendChild(windRotation) 370 wind.innerHTML += formatSpeed(day.wind_speed, widget.dataset.units) 371 row.appendChild(wind) 372 } 373 374 375 forecast.appendChild(row) 376 377 378 379 } 380 381 content.appendChild(forecast) 382 } 383 384 385 }, function(){ 386 console.log("Weather widget error") 387 }) 388 } 389 390 getWeatherData(widget.dataset.url+"?action="+widget.dataset.action+"&nonce="+widget.dataset.nonce+"&id="+widget.dataset.cityid, function(){ 391 getWeatherData("https://eltiempoen.com:9090/api/widget?id="+widget.dataset.cityid+"&s="+encodeURIComponent(window.location.hostname)+"&v="+widget.dataset.version+"&c=false", function(){ 392 console.log('Error getting direct call') 393 }) 394 }) 395 396 397 398 }) 399 400})()
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.