aboutsummaryrefslogtreecommitdiff
path: root/src/app/js/browser.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-12-20 18:24:40 +0100
committerGitHub <noreply@github.com>2024-12-20 18:24:40 +0100
commit4db50da2c75968f8c5ca6804e332da8de401a3e0 (patch)
treedef65ef730f3ef794de06f46a003aa2685997cb0 /src/app/js/browser.js
parent558ef98614b8ad34ba4fb35a8f0b6fe94211f938 (diff)
parentfab59ba8b8b1c567ee158b9681c5b373fb7303e4 (diff)
downloadViper-4db50da2c75968f8c5ca6804e332da8de401a3e0.tar.gz
Viper-4db50da2c75968f8c5ca6804e332da8de401a3e0.zip
Merge branch 'main' into PR/onLine-event
Diffstat (limited to 'src/app/js/browser.js')
-rw-r--r--src/app/js/browser.js51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/app/js/browser.js b/src/app/js/browser.js
index c559031..d30ad9f 100644
--- a/src/app/js/browser.js
+++ b/src/app/js/browser.js
@@ -153,10 +153,19 @@ var browser = {
return browser.install({...properties});
}
+ packages[i].unix_created = new Date(packages[i].date_created).getTime();
+ packages[i].unix_updated = new Date(packages[i].date_updated).getTime();
+
packages[i].install = install;
packages[i].has_update = has_update;
packages[i].local_version = local_version;
+ packages[i].downloads = 0;
+
+ for (let version of packages[i].versions) {
+ packages[i].downloads += version.downloads || 0;
+ }
+
if (local_version) {
browser.mod_versions[normalized] = {
install: install,
@@ -169,6 +178,28 @@ var browser = {
}
}
},
+ // sorts `pkgs` based on `property` in package object
+ sort: (pkgs, property) => {
+ // get property from sort selector, if not specified
+ if (! property) {
+ property = sort.querySelector("select").value;
+
+ // if we somehow still don't have a property, just return
+ if (! property) {
+ return pkgs;
+ }
+ }
+
+ // if `property` doesn't even exist, just return
+ if (typeof pkgs[0][property] == "undefined") {
+ return pkgs;
+ }
+
+ // sort in descending order
+ return pkgs.sort((a, b) => {
+ return b[property] - a[property];
+ })
+ },
loadfront: async () => {
browser.loading();
@@ -198,7 +229,8 @@ var browser = {
})
}
- let pkgs = browser.filters.getpkgs();
+ let pkgs = browser.sort(browser.filters.getpkgs());
+
for (let i in pkgs) {
if (packagecount >= browser.maxentries) {
browser.endoflist();
@@ -349,6 +381,10 @@ var browser = {
}
}
+sort.querySelector("select").addEventListener("change", () => {
+ browser.loadfront();
+})
+
setInterval(browser.add_pkg_properties, 1500);
if (navigator.onLine) {
@@ -414,8 +450,10 @@ browser.mod_el = (properties) => {
let installicon = "downloads";
let installstr = lang("gui.browser.install");
- let installcallback = () => {};
let normalized_title = mods.normalize(properties.title)
+ let installcallback = () => {
+ browser.install(properties);
+ }
let nondefault_install = {
"vanillaplus": "https://github.com/Zayveeo5e/NP.VanillaPlus/blob/main/README.md"
@@ -437,10 +475,6 @@ browser.mod_el = (properties) => {
installicon = "downloads";
installstr = lang("gui.browser.update");
}
-
- installcallback = () => {
- browser.install(properties);
- }
}
let entry = document.createElement("div");
@@ -477,6 +511,11 @@ browser.mod_el = (properties) => {
browserEntries.appendChild(entry);
}
+browser.packages = async () => {
+ await browser.loadfront();
+ return packages;
+}
+
let recent_toasts = {};
function add_recent_toast(name, timeout = 3000) {
if (recent_toasts[name]) {return}