1(function ($) { 2 'use strict'; 3 4 /* ----------------------------------------------------------- 5 * STRINGS 6 * ----------------------------------------------------------- */ 7 const TEXT = { 8 title: { 9 english: 'Weather in ', 10 french: 'Météo à ' 11 }, 12 sunrise: { 13 english: 'Sunrise: ', 14 french: 'Lever du soleil : ' 15 }, 16 sunset: { 17 english: 'Sunset: ', 18 french: 'Coucher du soleil : ' 19 }, 20 humidity: { 21 english: 'Humidity: ', 22 french: 'Humidité : ' 23 }, 24 wind: { 25 english: 'Wind Speed: ', 26 french: 'Vent : ' 27 }, 28 rain: { 29 spanish: 'Lluvia: ', 30 french: 'Risque de pluie : ' 31 } 32 }; 33 34 35 /* ----------------------------------------------------------- 36 * HELPERS 37 * ----------------------------------------------------------- */ 38 function ucfirst(str) { return str.charAt(0).toUpperCase() + str.slice(1); } 39 40 function t(key, lang) { 41 return TEXT[key][lang] || ''; 42 } 43 44 /* ----------------------------------------------------------- 45 * INITIALISE ONE WIDGET 46 * ----------------------------------------------------------- */ 47 function initWidget($w) { 48 const city = $w.attr('data-city'); 49 const country = $w.attr('data-country'); 50 const language = $w.attr('data-language') || 'french'; 51 const days = parseInt($w.attr('data-days'), 10) || 0; 52 const widthPref = $w.attr('data-width') === 'tight' ? 'tight' : 'maxwidth'; 53 const showCur = $w.attr('data-current') === 'on'; 54 const showWind = $w.attr('data-wind') === 'on'; 55 const showSun = $w.attr('data-sunrise') === 'on'; 56 const bg = $w.attr('data-background') || 'linear-gradient(to left,#d3dfff,#fbfcff)'; 57 const fg = $w.attr('data-text-color') || 'black'; 58 const place = city.replace(' ', '_') + ',' + country; 59 60 // --- create a hash of current config --- 61 const hash = JSON.stringify({ city, country, language, days, widthPref, showCur, showWind, showSun, bg, fg }); 62 63 // --- skip if already rendered with same hash --- 64 if ($w.attr('data-render-hash') === hash) return; 65 66 // --- mark this widget as rendered with hash --- 67 $w.attr('data-render-hash', hash); 68 69 $w.removeClass('tight maxwidth').addClass(widthPref); 70 71 $.getJSON( 72 'https://www.weatherwp.com/api/common/publicWeatherForLocation.php', 73 { city, country, place, domain: location.href, language, widget: 'French' } 74 ).done(resp => draw(resp)); 75 76 function draw(r) { 77 const wrap = $('<div>', { 78 class : `main_wrap`, 79 css : { background: bg, color: fg } 80 }); 81 82 $('<div>', { 83 class : 'weather_title', 84 html : t('title', language) + ucfirst(city) 85 }).appendTo(wrap); 86 87 if (showCur) { 88 const centre = $('<div>', { class: 'weather_center_wrap' }).appendTo(wrap); 89 90 $('<div>', { class: 'weather_image_wrap' }) 91 .append($('<img>', { class: 'weather_image', src: r.icon })) 92 .appendTo(centre); 93 94 $('<div>', { class: 'weather_temp_wrap' }) 95 .append($('<span>', { class: 'weather_temp', html: r.temp + '°' })) 96 .append($('<span>', { class: 'weather_temp_type', text: 'C' })) 97 .appendTo(centre); 98 99 $('<div>', { class: 'weather_description', text: r.description }) 100 .appendTo(wrap); 101 } 102 103 if (showSun) { 104 $('<div>', { 105 class : 'weather_sunrise', 106 text : t('sunrise', language) + r.sunrise 107 }).appendTo(wrap); 108 109 $('<div>', { 110 class : 'weather_sunset', 111 text : t('sunset', language) + r.sunset 112 }).appendTo(wrap); 113 } 114 115 if (showWind) { 116 const data = $('<div>', { class: 'weather_data_wrap' }).appendTo(wrap); 117 118 $('<div>', { 119 class : 'weather_humidity', 120 text : t('humidity', language) + r.humidity + '%' 121 }).appendTo(data); 122 123 $('<div>', { 124 class : 'weather_wind', 125 text : t('wind', language) + r.windspeedKmph + 'Kmph' 126 }).appendTo(data); 127 128 $('<div>', { 129 class : 'weather_rain', 130 text : t('rain', language) + r.chanceofrain + '%' 131 }).appendTo(data); 132 } 133 134 if (days > 0) { 135 const daysWrap = $('<div>', { class: 'weather_days_wrap' }).appendTo(wrap); 136 for (let i = 0; i < days; i++) { 137 const d = r.days[i];
138 const col = $('<div>', { class: 'weather_day_wrap' }).appendTo(daysWrap); 139 140 $('<div>', { class: 'weather_day_name', text: d.dayName }).appendTo(col); 141 $('<div>', { class: 'weather_day_image_wrap' }) 142 .append($('<img>', { class: 'weather_day_image', src: d.icon })) 143 .appendTo(col); 144 $('<div>', { 145 class : 'weather_day_temp', 146 html : `${d.max}°<span class="temp-separator">/</span>${d.min}°` 147 }).appendTo(col); 148 } 149 } 150 151 const link = $('<a>', { href: r.deepLink, target: '_blank' }); 152 if (r.deepLinkAlt) link.attr({ title: r.deepLinkAlt, 'aria-label': r.deepLinkAlt }); 153 link.append(wrap); 154 155 $w.find('.weather_widget_placeholder') 156 .empty() 157 .append(link); 158 } 159 } 160 161 /* ----------------------------------------------------------- 162 * INITIALISE ALL NOTâYETâDRAWN WIDGETS 163 * ----------------------------------------------------------- */ 164 function refresh() { 165 $('.meteo-widget').each(function () { initWidget($(this)); }); 166 $('.preview-weather-widget.meteo-widget').each(function () { 167 initWidget($(this)); 168 }); 169 document.querySelectorAll('iframe').forEach(frame => { 170 try { 171 const doc = frame.contentDocument || frame.contentWindow.document; 172 if (!doc) return; 173 174 $(doc).find('.preview-weather-widget.meteo-widget').each(function () { 175 initWidget($(this)); 176 }); 177 } catch (e) { 178 // Cross-origin or inaccessible iframe â safely skip 179 // console.warn('Skipping iframe due to CORS or sandbox:', e); 180 } 181 }); 182 } 183 window.refreshMeteoWidgets = refresh; 184 185 $(refresh); 186 187 window.addEventListener('weather-widget-refresh', refresh); 188 189})(jQuery);
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.