diff --git a/src/core/index/loop.js b/src/core/index/loop.js index 6b91b7d5..d0b5ed11 100644 --- a/src/core/index/loop.js +++ b/src/core/index/loop.js @@ -100,11 +100,9 @@ setInterval(() => { } }, 500); const _detection_list = Object.keys(detection_list).sort((a, b) => detection_list[a] - detection_list[b]); - for (let i = 0; i < Object.keys(detection_box).length; i++) { - const key = Object.keys(detection_box)[i]; + for (const key of Object.keys(detection_box)) { detection_box[key].remove(); delete detection_box[key]; - i--; } if (_detection_list.length) { setTimeout(() => { @@ -114,8 +112,7 @@ setInterval(() => { continue; } let passed = false; - for (let Index = 0; Index < Object.keys(TREM.EQ_list).length; Index++) { - const _key = Object.keys(TREM.EQ_list)[Index]; + for (const _key of Object.keys(TREM.EQ_list)) { const _data = TREM.EQ_list[_key].data; let SKIP = 0; for (let _i = 0; _i < 4; _i++) { @@ -343,8 +340,9 @@ setInterval(() => { if (drawer_lock) { return; } + const list = Object.keys(TREM.EQ_list); drawer_lock = true; - if (!Object.keys(TREM.EQ_list).length) { + if (!list.length) { eew(false); if (TREM.geojson) { TREM.geojson.remove(); @@ -384,8 +382,7 @@ setInterval(() => { let user_max_intensity = -1; let user_p_wave = 0; let user_s_wave = 0; - for (let i = 0; i < Object.keys(TREM.EQ_list).length; i++) { - const key = Object.keys(TREM.EQ_list)[i]; + for (const key of list) { const data = TREM.EQ_list[key].data; if (TREM.EQ_list[key].trem) { if (Now().getTime() - data.time > 240_000) { @@ -476,9 +473,13 @@ setInterval(() => { } const progress = Math.round(((Now().getTime() - data.time) / 1000 / TREM.EQ_list[key].wave[1].Stime) * 100); const progress_bar = `
`; + TREM.EQ_list[key].epicenterTooltip = true; TREM.EQ_list[key].epicenterIcon.bindTooltip(progress_bar, { opacity: 1, permanent: true, direction: "right", offset: [10, 0], className: "progress-tooltip" }); } else { - TREM.EQ_list[key].epicenterIcon.unbindTooltip(); + if (TREM.EQ_list[key].epicenterTooltip) { + TREM.EQ_list[key].epicenterIcon.unbindTooltip(); + delete TREM.EQ_list[key].epicenterTooltip; + } if (!TREM.EQ_list[key].s_wave) { TREM.EQ_list[key].s_wave = L.circle([data.lat, data.lon], { color : (data.type == "eew-report") ? "grey" : (data.type == "eew-trem") ? "#73BF00" : (TREM.EQ_list[key].alert) ? "red" : "#FF8000", @@ -512,8 +513,7 @@ setInterval(() => { if (key == show_eew_id) { TREM.eew_bounds = L.latLngBounds(); let _count = 0; - for (let _i = 0; _i < Object.keys(TREM.EQ_list[key].loc).length; _i++) { - const loc = Object.keys(TREM.EQ_list[key].loc)[_i]; + for (const loc of Object.keys(TREM.EQ_list[key].loc)) { if (TREM.EQ_list[key].loc[loc].pga > 0.8 && TREM.EQ_list[key].loc[loc].dist < s_dist / 1000) { _count++; const Loc = loc.split(" "); @@ -629,6 +629,7 @@ setInterval(() => { if (focus_lock && Date.now() - last_map_time < 60000) { return; } + const list = Object.keys(TREM.EQ_list); if (last_map_time) { last_map_time = 0; location_button.style.color = "grey"; @@ -638,15 +639,14 @@ setInterval(() => { refresh_report_list(); } let nsspe = true; - for (let i = 0; i < Object.keys(TREM.EQ_list).length; i++) { - const key = Object.keys(TREM.EQ_list)[i]; + for (const key of list) { if (!TREM.EQ_list[key].trem) { nsspe = false; break; } } if (!TREM.report_time) { - if (!Object.keys(TREM.EQ_list).length || nsspe) { + if (!list.length || nsspe) { if (TREM.rts_bounds._northEast == undefined) { if (Zoom && now_time() - Zoom_timestamp > 2500) { Zoom = false; @@ -661,8 +661,7 @@ setInterval(() => { } else { TREM.rts_bounds = L.latLngBounds(); const dist_list = []; - for (let i = 0; i < Object.keys(TREM.EQ_list).length; i++) { - const key = Object.keys(TREM.EQ_list)[i]; + for (const key of list) { if (TREM.EQ_list[key].trem) { continue; } diff --git a/src/core/index/rts.js b/src/core/index/rts.js index a17f9454..89de651c 100644 --- a/src/core/index/rts.js +++ b/src/core/index/rts.js @@ -51,8 +51,7 @@ async function get_station_info() { return; } ans = await ans.json(); - for (let i = 0; i < Object.keys(ans).length; i++) { - const uuid = Object.keys(ans)[i]; + for (const uuid of Object.keys(ans)) { ans[uuid].UUID = uuid; station[uuid.split("-")[2]] = ans[uuid]; } @@ -83,12 +82,10 @@ function on_rts_data(data) { let max_pga = 0; let max_intensity = 0; const detection_location = data.area ?? []; - for (let i = 0; i < Object.keys(station_icon).length; i++) { - const key = Object.keys(station_icon)[i]; + for (const key of Object.keys(station_icon)) { if (!data[key] || map_style_v == "3") { station_icon[key].remove(); delete station_icon[key]; - i--; } } let rts_sation_loc = " - - - - - "; @@ -96,15 +93,15 @@ function on_rts_data(data) { let rts_sation_intensity = "--"; let rts_sation_intensity_number = 0; detection_list = data.box ?? {}; - for (let i = 0; i < Object.keys(detection_list).length; i++) { - const key = Object.keys(detection_list)[i]; + for (const key of Object.keys(detection_list)) { if (max_intensity < detection_list[key]) { max_intensity = detection_list[key]; } } - for (let i = 0; i < Object.keys(data).length; i++) { - const uuid = Object.keys(data)[i]; + const list = Object.keys(TREM.EQ_list); + + for (const uuid of Object.keys(data)) { if (!station[uuid]) { continue; } @@ -176,7 +173,7 @@ function on_rts_data(data) { } } if (station_icon[uuid]) { - if ((Object.keys(TREM.EQ_list).length && !station_data.alert && !(map_style_v == "2" || map_style_v == "4")) || TREM.report_time) { + if ((list.length && !station_data.alert && !(map_style_v == "2" || map_style_v == "4")) || TREM.report_time) { station_icon[uuid].getElement().style.visibility = "hidden"; } else { station_icon[uuid].getElement().style.visibility = ""; @@ -304,7 +301,7 @@ function on_rts_data(data) { plugin.emit("trem.rts.pga-low"); } } - if (!Object.keys(TREM.EQ_list).length) { + if (!list.length) { document.getElementById("eew_title_text").innerHTML = (max_intensity >= 4) ? get_lang_string("detection.high") : (max_intensity >= 2) ? get_lang_string("detection.middle") : get_lang_string("detection.low"); document.getElementById("eew_box").style.backgroundColor = (max_intensity >= 4) ? "#E80002" : (max_intensity >= 2) ? "#C79A00" : "#149A4C"; let _text_1 = ""; @@ -334,12 +331,12 @@ function on_rts_data(data) { rts_show = false; TREM.rts_audio.intensity = -1; TREM.rts_audio.pga = 0; - if (!Object.keys(TREM.EQ_list).length) { + if (!list.length) { document.getElementById("eew_title_text").innerHTML = get_lang_string("eew.null"); } max_intensity_text.innerHTML = ""; max_intensity_text.className = ""; - if (!Object.keys(TREM.EQ_list).length) { + if (!list.length) { document.getElementById("eew_box").style.backgroundColor = "#333439"; clear_eew_box(detection_location_1, detection_location_2); } @@ -358,7 +355,7 @@ function on_rts_data(data) { i_list.time = Date.now(); } if (i_list.time && Date.now() - i_list.time > 60000) { - if (!Object.keys(TREM.EQ_list).length) { + if (!list.length) { i_list.data = []; } i_list.time = 0; @@ -370,8 +367,7 @@ function on_rts_data(data) { const city_I = {}; for (let i = 0; i < i_list.data.length; i++) { let loc = ""; - for (let index = 0; index < Object.keys(station).length; index++) { - const uuid = Object.keys(station)[index]; + for (const uuid of Object.keys(station)) { if (i_list.data[i].uuid.includes(uuid)) { loc = station[uuid].Loc; break; @@ -385,14 +381,15 @@ function on_rts_data(data) { city_I[_loc] = i_list.data[i].intensity; } } - for (let i = 0; i < Object.keys(city_I).length; i++) { - if (i > 7) { - break; - } - const city = Object.keys(city_I)[i]; + const cities = Object.keys(city_I); + const maxItems = Math.min(8, cities.length); + + for (let i = 0; i < maxItems; i++) { + const city = cities[i]; + const intensity = int_to_intensity(city_I[city]); const intensity_list_item = document.createElement("intensity_list_item"); intensity_list_item.className = "intensity_list_item"; - intensity_list_item.innerHTML = `
${int_to_intensity(city_I[city])}
${city}
`; + intensity_list_item.innerHTML = `
${intensity}
${city}
`; intensity_list.appendChild(intensity_list_item); } } else { @@ -403,8 +400,7 @@ function on_rts_data(data) { const intensity_list_item = document.createElement("intensity_list_item"); intensity_list_item.className = "intensity_list_item"; let loc = ""; - for (let index = 0; index < Object.keys(station).length; index++) { - const uuid = Object.keys(station)[index]; + for (const uuid of Object.keys(station)) { if (i_list.data[i].uuid.includes(uuid)) { loc = station[uuid].Loc; break; @@ -420,14 +416,13 @@ function on_rts_data(data) { } else { intensity_list.style.visibility = "hidden"; } - if (Object.keys(TREM.EQ_list).length || data.Alert) { + if (list.length || data.Alert) { show_icon(true); } else if (!TREM.report_time) { show_icon(false); } let level = 0; - for (let i = 0; i < Object.keys(level_list).length; i++) { - const uuid = Object.keys(level_list)[i]; + for (const uuid of Object.keys(level_list)) { level += level_list[uuid]; } document.getElementById("intensity_level_num").textContent = Math.round(level);