- Minecraft
- Version
- Loader Type
-
+ Minecraft
+ Version
+ Type
+
@@ -2130,7 +2055,7 @@ function uri($uri) {
Version
Minecraft
Loader
- File
+ File
@@ -2144,7 +2069,7 @@ function uri($uri) {
scope="row">Unknown' : $mod['version'] ?>
>Unknown' : $mod['mcversion'] ?>
>Unknown' : $mod['loadertype'] ?>
- >Unknown' : $mod['filename'] ?>
+ class="d-none d-md-table-cell">Unknown' : $mod['filename'] ?>
= 0 : compareStart > 0;
+ const inUpperBound = endInclusive ? compareEnd <= 0 : compareEnd < 0;
+
+ return inLowerBound && inUpperBound;
+}
+
function slugify (str) {
str = str.replace(/^\s+|\s+$/g, '');
str = str.toLowerCase();
@@ -56,10 +78,13 @@ function isLocalStorageAvailable(){
}
}
function get_cached(key) {
+ if (havelocalstorage==null) {
+ havelocalstorage=isLocalStorageAvailable()
+ }
if (havelocalstorage) {
if (key in localStorage) {
tv = JSON.parse(localStorage[key]);
- if (Math.round(Date.now() / 1000) < tv[0]) {
+ if (tv[0]==-1 || Math.round(Date.now() / 1000) < tv[0]) {
return tv[1];
} else {
localStorage.removeItem(key)
@@ -74,10 +99,17 @@ function get_cached(key) {
}
}
}
-function set_cached(key,value) {
+function set_cached(key,value,ttl) {
+ if (havelocalstorage==null) {
+ havelocalstorage=isLocalStorageAvailable()
+ }
// cache for 30 mins
if (havelocalstorage) {
- timestamp = Math.round(Date.now() / 1000)+1800;
+ if (ttl==Infinity||ttl==-1) {
+ var timestamp = -1;
+ } else {
+ var timestamp = Math.round(Date.now() / 1000)+ttl;
+ }
val=JSON.stringify([timestamp, value]);
localStorage[key]=val
return value;
diff --git a/resources/js/page_build.js b/resources/js/page_build.js
index fc4a93e..abfbef1 100644
--- a/resources/js/page_build.js
+++ b/resources/js/page_build.js
@@ -59,67 +59,129 @@ function add_o(id) {
request.open("GET", "./functions/add-mod.php?bid="+build_id+"&id="+id);
request.send();
}
-function add(name, v, mcv) {
+function add(name, id, v, mcv) {
if ($("#versionselect-"+name+' option:selected').attr('missing')=='true') {
return;
}
if ($("#versionselect-"+name).val()==null) {
return;
}
- $("#btn-add-mod-"+name).attr("disabled", true);
$("#versionselect-"+name).attr("disabled", true);
- $("#cog-"+name).show();
- let id = $("#versionselect-"+name).val();
+ $("#btn-add-mod-"+name).attr("disabled", true);
+ // $('#btn-add-mod-'+name).html('');
+
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
if (request.responseText=="Mod added") {
- // $("#mod-add-row-"+name).remove();
- $("#cog-"+name).hide();
- $("#check-"+name).show();
+ $("#mod-add-row-"+name).remove();
+ // $('#btn-add-mod-'+name).html(' ');
// remember to modify index.php/build too
$("#mods-in-build").append(`
${name}
${v}
- ${mcv}
+ ${mcv}
-
+
-
-
-
`);
} else {
- $("#cog-"+name).hide();
- $("#times-"+name).show();
+ // $('#btn-add-mod-'+name).html('Add to build');
}
}
};
- request.open("GET", "./functions/add-mod.php?bid="+build_id+"&id="+$("#versionselect-"+name).val());
+ console.log("./functions/add-mod.php?bid="+build_id+"&id="+id)
+ request.open("GET", "./functions/add-mod.php?bid="+build_id+"&id="+id);
request.send();
}
-$("#search").on('keyup',function(){
- tr = document.getElementById("modstable").getElementsByTagName("tr");
- for (var i = 0; i < tr.length; i++) {
+function add_mod_row(id,pretty_name,name,vs,mcv) {
+ if (pretty_name=='' || name=='' || versions=='' || mcv=='') {
+ var addbutton=`Issue(s) `;
+ } else {
+ var addbutton=`Add to build `;
+ }
+
+ var vs_str = ``;
+ for (let v of vs) {
+ vs_str += `${v} `;
+ }
- td = tr[i].getElementsByTagName("td")[0];
- if (td) {
+ $('#build-available-mods').append(`
+
+ ${pretty_name}
+ ${vs_str}
+
+ ${addbutton}
+
+
+ `);
+}
- console.log(td);
- console.log(td.innerHTML.toUpperCase())
- if (td.innerHTML.toUpperCase().indexOf($("#search").val().toUpperCase()) > -1) {
- tr[i].style.display = "";
- } else {
- tr[i].style.display = "none";
+function parsemods(obj) {
+ let showall = $('#showall').is(':checked');
+ let added_num=0;
+
+ let vs={};
+ for (let mod of obj) {
+ if (mod['name'] in vs) {
+ vs[mod['name']].push(mod['version']);
+ } else {
+ vs[mod['name']]=[mod['version']];
+ }
+ }
+ let filter=$("#search").val();
+ for (let mod of obj) {
+ if (filter=='' || filter==undefined || mod['pretty_name'].toLowerCase().includes(filter)||mod['name'].toLowerCase().includes(filter)) {
+ if (mod['mcversion']=='' || mcv==mod['mcversion'] || isVersionInInterval(`'${mcv}'`, mod['mcversion']) || showall) {
+ add_mod_row(mod['id'], mod['pretty_name'],mod['name'],vs[mod['name']],mcv);
+ added_num+=1;
}
}
}
+ if (added_num==0) {
+ if (filter!='') {
+ $('#no-mods-available-search-results').show();
+ } else {
+ $('#no-mods-available').show();
+ }
+ }
+}
+
+async function getmods() {
+ return new Promise((resolve, reject) => {
+ $('#build-available-mods').empty();
+ $('#no-mods-available').hide();
+ $('#no-mods-available-search-results').hide();
+ if (get_cached('available_mods')) {
+ parsemods(JSON.parse(get_cached('available_mods')));
+ } else {
+ var request = new XMLHttpRequest();
+ request.onreadystatechange = function() {
+ if (request.readyState == 4 && request.status == 200) {
+ set_cached('available_mods',request.responseText,30);
+ parsemods(JSON.parse(request.responseText));
+ resolve(true)
+ }
+ }
+ request.onerror = function() {
+ console.log('could not get mods from api');
+ reject(false)
+ }
+ request.open("GET", 'api/mod');
+ request.send();
+ }
+ });
+}
+
+$("#search").on('keyup', async function(){
+ await getmods(); // get mods on type
+
});
$("#search2").on('keyup',function(){
tr = document.getElementById("filestable").getElementsByTagName("tr");
@@ -140,18 +202,15 @@ $("#search2").on('keyup',function(){
}
});
$('#showall').change(function() {
- var request = new XMLHttpRequest();
- request.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- window.location.reload();
- }
- };
- if ( $('#showall').is(':checked') ) {
- request.open("GET", "./functions/change_show_all.php?showall=true");
+ if ($('#showall').is(':checked')) {
+ $('#mods-for-version-string').text(' for Minecraft '+mcv);
+ $('#mods-for-version-string').show();
} else {
- request.open("GET", "./functions/change_show_all.php?showall=false");
+ $('#mods-for-version-string').hide();
}
- request.send();
+
+ set_cached('showall', $('#showall').is(':checked'), -1);
+ getmods(mcv, type);
});
$(document).on('change', '.form-control', function() {
@@ -169,4 +228,9 @@ $(document).on('change', '.form-control', function() {
}
console.log('#btn-add-mod-'+modid);
}
+});
+
+$(document).ready(function() {
+ $('#showall').prop('checked', get_cached('showall'));
+ getmods();
});
\ No newline at end of file
diff --git a/resources/js/page_lib-mods.js b/resources/js/page_lib-mods.js
index 97088b7..7d6929b 100644
--- a/resources/js/page_lib-mods.js
+++ b/resources/js/page_lib-mods.js
@@ -108,7 +108,7 @@ function sendFile(file, i) {
$('#table-available-mods').append(`
${pretty_name[i]}
- ${author[i]}
+ ${author[i]}
${num_versions}
@@ -189,9 +189,9 @@ function addrow(hit) {
var row = `
${hit['title']}
- ${categories}
+ ${categories}
${description}
- ${author}
+ ${author}
${btn}
`;
@@ -202,7 +202,7 @@ function getdescription(id) {
if (id in details) {
console.log('got cached details');
showdetails(id);
- } else if (havelocalstorage && 'details_'+id in localStorage) {
+ } else if (get_cached('details_'+id)) {
console.log('got cached details from localstorage');
details[id]=JSON.parse(localStorage['details_'+id]);
showdetails(id);
@@ -216,9 +216,7 @@ function getdescription(id) {
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
let obj = JSON.parse(request.responseText);
- if (havelocalstorage && !(id in localStorage)) {
- localStorage['details_'+id]=request.responseText;
- }
+ set_cached('details_'+id, request.responseText,1800);
details[id]=obj;
console.log('got new description');
showdetails(id);
@@ -280,7 +278,7 @@ async function getversions(id) {
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
let obj = JSON.parse(request.responseText);
- set_cached('versions_'+id, request.responseText);
+ set_cached('versions_'+id, request.responseText, 1800);
console.log('got new versions for id='+id);
versions[id] = obj;
@@ -348,6 +346,9 @@ function installmod() {
console.log(url);
+ let mcv = $('#mcv option:selected').attr('mc');
+ let type = $('#mcv option:selected').attr('type');
+
var request = new XMLHttpRequest();
var postdata=new FormData();
postdata.append('url',url);
@@ -355,6 +356,9 @@ function installmod() {
var filename=url.substring(url.lastIndexOf('/') + 1);
postdata.append('filename', filename);
}
+ postdata.append('fallback_mcversion', mcv);
+ // postdata.append('fallback_type', type);
+
request.open("POST", "./functions/send_mods.php", true);
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
@@ -402,7 +406,7 @@ function installmod() {
$('#table-available-mods').append(`
${pretty_name[i]}
- ${author[i]}
+ ${author[i]}
${num_versions}
@@ -526,7 +530,7 @@ $('#searchbutton').on('click', async function() {
results[searchquery]=hits;
- set_cached(searchquery, hits);
+ set_cached(searchquery, hits, 1800);
} else {
console.log('no hits');
@@ -561,9 +565,4 @@ $(document).ready(function() {
installed=fetch_installed()
loop_count+=1
}
- let loop_count2=0;
- while (havelocalstorage==null && loop_count2 < 3) {
- havelocalstorage = isLocalStorageAvailable();
- loop_count2+=1
- }
});
diff --git a/resources/js/page_modloaders.js b/resources/js/page_modloaders.js
index eb87c47..2f826d4 100644
--- a/resources/js/page_modloaders.js
+++ b/resources/js/page_modloaders.js
@@ -288,7 +288,7 @@ async function chf(link,name,id,mc) {
${mc}
${name}
- ${link}
+ ${link}
Add to Database
`);
diff --git a/resources/js/page_modpack.js b/resources/js/page_modpack.js
index 2d4a5ff..f6e91d3 100644
--- a/resources/js/page_modpack.js
+++ b/resources/js/page_modpack.js
@@ -18,7 +18,7 @@ $("#mplist").change(function() {
});
$("#newbname").on("keyup",function(){
- if (sbna.indexOf($("#newbname").val())==false) {
+ if (sbna.includes($("#newbname").val())) {
$("#newbname").addClass("is-invalid");
$("#warn_newbname").show();
$("#create1").prop("disabled",true);
@@ -31,7 +31,7 @@ $("#newbname").on("keyup",function(){
}
});
$("#newname").on("keyup",function(){
- if (sbna.indexOf($("#newname").val())==false) {
+ if (sbna.includes($("#newname").val())) {
$("#newname").addClass("is-invalid");
$("#warn_newname").show();
$("#copybutton").prop("disabled",true);
@@ -42,7 +42,7 @@ $("#newname").on("keyup",function(){
}
});
- function edit(id) {
+function edit(id) {
window.location = "./build?id="+id;
}
function remove_box(id,name) {
@@ -102,6 +102,14 @@ function remove(id) {
$("#latest-mc-li").hide();
}
+ for (let b of bd) {
+ if (b['id']==id) {
+ let name=b['name'];
+ bd.splice(bd.indexOf(b),1);
+ sbna.splice(sbna.indexOf(name),1);
+ }
+ }
+
}
};
// request.open("GET", "./functions/delete-build.php?id="+id+"&pack=");