Skip to content

Commit

Permalink
refactor: object
Browse files Browse the repository at this point in the history
  • Loading branch information
whes1015 committed Oct 15, 2023
1 parent b7c7a49 commit fa01d3a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 37 deletions.
18 changes: 6 additions & 12 deletions src/core/index/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ function replay_stop() {
alert_timestamp = 0;
rts_replay_timestamp = 0;
report_now_id = 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 Object.keys(TREM.EQ_list)) {
if (TREM.EQ_list[key].epicenterIcon) {
TREM.EQ_list[key].epicenterIcon.remove();
}
Expand Down Expand Up @@ -488,8 +487,7 @@ function replay_run() {
for (const item of document.getElementsByClassName("report_click_text fa-regular fa-circle-play fa-2x")) {
item.style.display = "none";
}
for (let i = 0; i < Object.keys(TREM.EQ_list).length; i++) {
const key = Object.keys(TREM.EQ_list)[i];
for (const key of Object.keys(TREM.EQ_list)) {
if (TREM.EQ_list[key].epicenterIcon) {
TREM.EQ_list[key].epicenterIcon.remove();
}
Expand Down Expand Up @@ -539,10 +537,8 @@ function eew_location_intensity(data, depth) {
const json = {};
let eew_max_pga = 0;
let count = 0;
for (let i = 0; i < Object.keys(region).length; i++) {
const city = Object.keys(region)[i];
for (let index = 0; index < Object.keys(region[city]).length; index++) {
const town = Object.keys(region[city])[index];
for (const city of Object.keys(region)) {
for (const town of Object.keys(region[city])) {
const info = region[city][town];
const dist_surface = Math.sqrt(pow((data.lat - info.lat) * 111) + pow((data.lon - info.lon) * 101));
const dist = Math.sqrt(pow(dist_surface) + pow(data.depth));
Expand Down Expand Up @@ -831,10 +827,8 @@ function time_replay(time) {
}

function code_to_town(code) {
for (let i = 0; i < Object.keys(region).length; i++) {
const city = Object.keys(region)[i];
for (let index = 0; index < Object.keys(region[city]).length; index++) {
const town = Object.keys(region[city])[index];
for (const city of Object.keys(region)) {
for (const town of Object.keys(region[city])) {
const info = region[city][town];
if (info.code == code) {
return {
Expand Down
27 changes: 12 additions & 15 deletions src/core/index/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ function on_eew(data, type) {
report_off();
}
data._time = data.time;
if (!Object.keys(TREM.EQ_list).length) {
const _eq_list = Object.keys(TREM.EQ_list);
if (!_eq_list.length) {
document.getElementById("detection_location_1").innerHTML = "";
document.getElementById("detection_location_2").innerHTML = "";
}
Expand Down Expand Up @@ -366,8 +367,7 @@ function on_eew(data, type) {

let epicenterIcon;
const eq_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 _eq_list) {
if (!TREM.EQ_list[key].trem) {
eq_list.push(key);
}
Expand Down Expand Up @@ -413,8 +413,7 @@ function on_eew(data, type) {
}
const _loc_list = TREM.EQ_list[data.id].loc;
let loc_list = "";
for (let i = 0; i < Object.keys(_loc_list).length; i++) {
const loc = Object.keys(_loc_list)[i];
for (const loc of Object.keys(_loc_list)[i]) {
if (loc == "max_pga") {
continue;
}
Expand Down Expand Up @@ -466,8 +465,8 @@ function _speech_eew() {

function draw_intensity(skip) {
const location_intensity = {};
for (let _i = 0; _i < Object.keys(TREM.EQ_list).length; _i++) {
const _key = Object.keys(TREM.EQ_list)[_i];
const eq_list = Object.keys(TREM.EQ_list);
for (const _key of eq_list) {
if (TREM.EQ_list[_key].data.cancel || TREM.EQ_list[_key].trem) {
continue;
}
Expand All @@ -481,8 +480,7 @@ function draw_intensity(skip) {
break;
}
}
for (let i = 0; i < Object.keys(TREM.EQ_list[_key].loc).length; i++) {
const key = Object.keys(TREM.EQ_list[_key].loc)[i];
for (const key of Object.keys(TREM.EQ_list[_key].loc)) {
if (key != "max_pga") {
const intensity = pga_to_intensity(TREM.EQ_list[_key].loc[key].pga);
if ((location_intensity[key] ?? 0) < intensity) {
Expand Down Expand Up @@ -511,7 +509,7 @@ function draw_intensity(skip) {
if (item_map_style == "3" || item_map_style == "4") {
return;
}
if (!(Object.keys(TREM.EQ_list).length == 1 && TREM.EQ_list[Object.keys(TREM.EQ_list)[0]].data.cancel)) {
if (!(eq_list.length == 1 && TREM.EQ_list[eq_list[0]].data.cancel)) {
TREM.geojson = geoJsonMap(tw_geojson, {
minZoom : 4,
maxZoom : 12,
Expand Down Expand Up @@ -552,8 +550,7 @@ function report_off() {
}
delete TREM.report_epicenterIcon;
delete TREM.report_epicenterIcon_trem;
for (let i = 0; i < Object.keys(TREM.report_icon_list).length; i++) {
const key = Object.keys(TREM.report_icon_list)[i];
for (const key of Object.keys(TREM.report_icon_list)) {
TREM.report_icon_list[key].remove();
}
TREM.report_icon_list = {};
Expand Down Expand Up @@ -684,10 +681,10 @@ function on_trem(data, type) {
if (data.cancel) {
TREM.EQ_list[data.id].data.timestamp = Now().getTime() - 75_000;
}
if (Object.keys(data.intensity).length) {
const intensity_list = Object.keys(data.intensity);
if (intensity_list.length) {
const location_intensity = {};
for (let i = 0; i < Object.keys(data.intensity).length; i++) {
const Int = Object.keys(data.intensity)[i];
for (const Int of intensity_list) {
for (let I = 0; I < data.intensity[Int].length; I++) {
const loc = code_to_town(data.intensity[Int][I]);
if (!loc) {
Expand Down
6 changes: 2 additions & 4 deletions src/core/index/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ TREM.Maps.main = L.map("map", {
TREM.size = (Number(TREM.Maps.main.getZoom().toFixed(1)) - 7.8) * 2;
TREM.Maps.main.on("zoomend", () => {
TREM.size = (Number(TREM.Maps.main.getZoom().toFixed(1)) - 7.8) * 2;
for (let i = 0; i < Object.keys(TREM.EQ_list).length; i++) {
const key = Object.keys(TREM.EQ_list)[i];
for (const key of Object.keys(TREM.EQ_list)) {
const data = TREM.EQ_list[key].data;
const icon = TREM.EQ_list[key].epicenterIcon.options.icon;
if (TREM.EQ_list[key].trem) {
Expand All @@ -75,8 +74,7 @@ TREM.Maps.main.on("zoomend", () => {
TREM.EQ_list[key].epicenterIcon.bindTooltip(TREM.EQ_list[key].epicenterIcon._tooltip._content, { opacity: 1, permanent: true, direction: "right", offset: [10, 0], className: "progress-tooltip" });
}
}
for (let i = 0; i < Object.keys(TREM.report_icon_list).length; i++) {
const key = Object.keys(TREM.report_icon_list)[i];
for (const key of Object.keys(TREM.report_icon_list)) {
const icon_info = TREM.report_icon_list[key];
const icon = icon_info.options.icon;
let size = 30 + TREM.size * 3;
Expand Down
3 changes: 1 addition & 2 deletions src/core/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ fs.readdirSync(path.join(app.getAppPath(), "./resource/lang/")).forEach((file, i
tw_lang_data = JSON.parse(fs.readFileSync(path.resolve(app.getAppPath(), `./resource/lang/${path.parse(file).name}/${path.parse(file).name}.json`)).toString());
try {
lang_data = JSON.parse(fs.readFileSync(path.resolve(app.getAppPath(), `./resource/lang/${path.parse(file).name}/${path.parse(file).name}.json`)).toString());
for (let I = 0; I < Object.keys(lang_data).length; I++) {
const id = Object.keys(lang_data)[I];
for (const id of Object.keys(lang_data)) {
try {
const item = document.getElementById(id);
item.textContent = lang_data[id];
Expand Down
3 changes: 1 addition & 2 deletions src/core/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ function load_plugin() {
log(`Plugin failed to load (${pluginName}) >> dependencies (TREM) too old (${app.getVersion()} => ^${dependencies.trem})`, 3, "plugin", "load_plugin");
} else {
let skip = false;
for (let I = 0; I < Object.keys(dependencies).length; I++) {
const name = Object.keys(dependencies)[I];
for (const name of Object.keys(dependencies)) {
if (!pluginInfo[name]) {
error = true;
skip = true;
Expand Down
3 changes: 1 addition & 2 deletions src/core/setting/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ function rts_list() {
function search_near_rts(lon, lat) {
let min = 0;
let name = "";
for (let i = 0; i < Object.keys(rts_list_data).length; i++) {
const id = Object.keys(rts_list_data)[i];
for (const id of Object.keys(rts_list_data)) {
const dist_surface = Math.sqrt(pow((lat - rts_list_data[id].Lat) * 111) + pow((lon - rts_list_data[id].Long) * 101));
if (!min || min > dist_surface) {
min = dist_surface;
Expand Down

0 comments on commit fa01d3a

Please sign in to comment.