From ceb90ab941a159d63ea5cace1c24dde6b8b96a86 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 8 Jun 2024 18:26:13 +0200 Subject: move browser.js' normalize() into mods.js --- src/app/js/browser.js | 34 ++++++++-------------------------- src/app/js/mods.js | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/app/js/browser.js b/src/app/js/browser.js index 9a1298a..ec5a31d 100644 --- a/src/app/js/browser.js +++ b/src/app/js/browser.js @@ -111,7 +111,7 @@ var Browser = { add_pkg_properties: () => { for (let i = 0; i < packages.length; i++) { let properties = packages[i]; - let normalized = normalize(packages[i].name); + let normalized = mods.normalize(packages[i].name); let has_update = false; let local_name = false; @@ -123,7 +123,7 @@ var Browser = { for (let ii = 0; ii < mods.list().all.length; ii++) { let mod = mods.list().all[ii]; - if (normalize(mod.name) !== normalized && ( + if (mods.normalize(mod.name) !== normalized && ( ! mod.package || mod.package.author + "-" + mod.package.package_name !== packages[i].full_name @@ -266,7 +266,7 @@ var Browser = { } }, setbutton: (mod, string, icon) => { - mod = normalize(mod); + mod = mods.normalize(mod); if (browserEntries.querySelector(`#mod-${mod}`)) { let elems = browserEntries.querySelectorAll(`.el#mod-${mod}`); @@ -289,13 +289,13 @@ var Browser = { setTimeout(() => { for (let i = 0; i < mods.list().all.length; i++) { - let modname = normalize(mods.list().all[i].name); - let modfolder = normalize(mods.list().all[i].folder_name); + let modname = mods.normalize(mods.list().all[i].name); + let modfolder = mods.normalize(mods.list().all[i].folder_name); if (mod.includes(modname)) { if (! make(modname)) { if (mods.list().all[i].manifest_name) { - make(normalize(mods.list().all[i].manifest_name)); + make(mods.normalize(mods.list().all[i].manifest_name)); } } } @@ -406,7 +406,7 @@ function BrowserEl(properties) { let normalized_mods = []; for (let i = 0; i < mods.list().all; i++) { - normalized_mods.push(normalize(mods_list[i].name)); + normalized_mods.push(mods.normalize(mods_list[i].name)); } if (properties.pkg.local_version) { @@ -421,7 +421,7 @@ function BrowserEl(properties) { let entry = document.createElement("div"); entry.classList.add("el"); - entry.id = `mod-${normalize(properties.title)}`; + entry.id = `mod-${mods.normalize(properties.title)}`; entry.innerHTML = `
@@ -545,24 +545,6 @@ ipcRenderer.on("installed-mod", (event, mod) => { } }) -function normalize(items) { - let main = (string) => { - return string.replaceAll(" ", "") - .replaceAll(".", "").replaceAll("-", "") - .replaceAll("_", "").toLowerCase(); - } - if (typeof items == "string") { - return main(items); - } else { - let newArray = []; - for (let i = 0; i < items.length; i++) { - newArray.push(main(items[i])); - } - - return newArray; - } -} - let searchtimeout; let searchstr = ""; let search = document.querySelector("#browser .search"); diff --git a/src/app/js/mods.js b/src/app/js/mods.js index caa66a7..7110d7e 100644 --- a/src/app/js/mods.js +++ b/src/app/js/mods.js @@ -29,7 +29,7 @@ mods.load = (mods_obj) => { name = mod.package.package_name; } - let normalized_name = "mod-list-" + normalize(name); + let normalized_name = "mod-list-" + mods.normalize(name); normalized_names.push(normalized_name); @@ -302,6 +302,23 @@ mods.is_installed = (modname) => { return false; } +mods.normalize = (items) => { + let main = (string) => { + return string.replaceAll(" ", "") + .replaceAll(".", "").replaceAll("-", "") + .replaceAll("_", "").toLowerCase(); + } + if (typeof items == "string") { + return main(items); + } else { + let newArray = []; + for (let i = 0; i < items.length; i++) { + newArray.push(main(items[i])); + } + + return newArray; + } +} // updates the installed mods ipcRenderer.on("mods", (event, mods_obj) => { -- cgit v1.2.3