diff --git a/assets/random.png b/assets/random.png new file mode 100644 index 0000000..ed60adc Binary files /dev/null and b/assets/random.png differ diff --git a/html/filters.html b/html/filters.html index 0d5b4b9..ddf2d73 100644 --- a/html/filters.html +++ b/html/filters.html @@ -49,13 +49,11 @@
- - - -
- - - + +
+ + +
diff --git a/html/search.html b/html/search.html index d36f86d..a1ecb60 100644 --- a/html/search.html +++ b/html/search.html @@ -41,6 +41,17 @@
+ +
@@ -64,7 +75,11 @@
- + +
+ +
@@ -110,7 +125,11 @@ let gauntlets = ["Fire", "Ice", "Poison", "Shadow", "Lava", "Bonus", "Chaos", "D let page = 0 let pages = 0 +let results = 0 let legalPages = true +let superSearch = ['*', '?type=mostliked', '*?type=mostdownloaded', '*?type=recent'].includes(window.location.href.split('/')[4].toLowerCase()) + +let searchFilters = `../api/search/${type == 'saved' ? JSON.parse(localStorage.getItem('saved') || '[]').reverse().toString() : accID || path}?page=${page}${window.location.search.replace("?", "&").replace("page", "nope")}` function Append(firstLoad) { @@ -123,7 +142,7 @@ function Append(firstLoad) { if (page == 0) $('#pageDown').hide() else $('#pageDown').show() - fetch(`../api/search/${type == 'saved' ? JSON.parse(localStorage.getItem('saved') || '[]').reverse().toString() : accID || path}?page=${page}${window.location.search.replace("?", "&").replace("page", "nope")}`).then(res => res.json()).then(res => { + fetch(searchFilters).then(res => res.json()).then(res => { if (res == '-1' || (res.length < 9 && type != "recent")) $('#pageUp').hide() else $('#pageUp').show() @@ -132,8 +151,17 @@ function Append(firstLoad) { if (firstLoad) { pages = res[0].pages - if (res.length < 9 && res.length > 0) pages = 1 - else if (pages > 999 || pages < 1) pages = null + results = res[0].results + if (res.length < 9 && res.length > 0) { + pages = 1 + results = res.length + } + else if (pages > 999 || pages < 1) { + pages = null + if (!superSearch) $('#shuffle').addClass('grayscale') + else $('#shuffle').css('filter', 'hue-rotate(100deg)') + } + $('#shuffle').show() $('#pagenum').text(`Page 1${pages ? ` of ${pages}` : ""}`) } @@ -234,6 +262,36 @@ $('#pageSelect').on('blur', function () { if ($(this).val() != "") $(this).val(Math.max(Math.min(Math.floor(x), max), min)); }); +$('#shuffle').click(function() { + if (superSearch) { + $('#searchBox').html('
') + $('#loading').show() + fetch("../api/search/*?page=0&type=recent").then(res => res.json()).then(recent => { + let mostRecent = recent[0].id + function fetchRandom() { + fetch(`../api/level/${Math.floor(Math.random() * (mostRecent)) + 1}`).then(res => res.json()).then(res => { + if (res == "-1" || !res.id) return fetchRandom() + else window.location.href = "../" + res.id + }) + } + fetchRandom() + }) + } + else if (pages) { + let random = {} + randomResult = Math.floor(Math.random() * (results)) + 1 + randomPage = Math.ceil(randomResult / 10) + randomIndex = randomResult % 10 + if (randomIndex == 0) randomIndex = 10 + $('#searchBox').html('
') + $('#loading').show() + fetch(searchFilters.replace(/(\?page=)\d+/, `$1${randomPage-1}`)).then(res => res.json()).then(res => { + window.location.href = "../" + res[randomIndex].id + }) + } + else return $('#shuffleDiv').show() +}) + $(document).keydown(function(k) { if (loading) return;