From 2813577c4c59c4bc486be0a6601e187ff36a0a41 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 27 Aug 2019 17:39:58 +0200 Subject: [PATCH] first fersion of algo finished --- sortt.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/sortt.js b/sortt.js index a8dc120..7b121ac 100644 --- a/sortt.js +++ b/sortt.js @@ -20,6 +20,10 @@ window.sortt=function(normsort,revsort,isdefault){ if (!(typeof isdefault === 'boolean')) isdefault = false; // parse URL + /* script check if url has already a sort= + NO: if sort=“” indikates default (with * prefix) set url_sort= + YES: set url_sort variable + */ url_sort=""; if (window.location.search.indexOf("sort=") < 0) { if ( isdefault ) url_sort = normsort; @@ -28,8 +32,32 @@ window.sortt=function(normsort,revsort,isdefault){ url_sort=url_sort.substr(0,url_sort.indexOf("&")); } + // generate new URL + /* script check if url_sort and sort attribute is same + YES: check if reverse attribute exist -> YES: generate URL with reverse sort param and open + NO: generate URL with sort param and open + */ + url_new = window.location.protocol + "//" + window.location.host + window.location.pathname; + if (window.location.search.length == 0) { + if (url_sort != normsort) { + url_new += "?sort=" + normsort + } else if (revsort != "") { + url_new += "?sort=" + revsort + } + } else { + tmp = window.location.search.substr(window.location.search.indexOf("sort=")+5); + if (tmp.indexOf("&") >= 0) { + tmp = tmp.substr(tmp.indexOf("&")); + } else { + tmp = ""; + } + if (url_sort != normsort) { + url_new = tmp.substr(0,window.location.search.indexOf("sort=")+5) + normsort + tmp; + } else if (revsort != "") { + url_new = tmp.substr(0,window.location.search.indexOf("sort=")+5) + revsort + tmp; + } + } - - //window.location.replace("http://localhost:3000/admin/repos?sort=feweststars&q=&tab="); + window.location.replace(url_new); };