From 1ffb95d819c8b601439b8b79b5357ec1c835118e Mon Sep 17 00:00:00 2001 From: Ninjapikachushka Date: Sun, 12 Jan 2025 18:39:16 +0300 Subject: [PATCH] 516vv --- code/datums/datumvars.dm | 195 ++++++++++++++------------------------- 1 file changed, 67 insertions(+), 128 deletions(-) diff --git a/code/datums/datumvars.dm b/code/datums/datumvars.dm index 193d450071f..3f8d27f4fbb 100644 --- a/code/datums/datumvars.dm +++ b/code/datums/datumvars.dm @@ -43,106 +43,45 @@ function updateSearch(){ var filter_text = document.getElementById('filter'); var filter = filter_text.value.toLowerCase(); - - if(event.keyCode == 13){ //Enter / return - var vars_ol = document.getElementById('vars'); - var lis = vars_ol.getElementsByTagName("li"); - for ( var i = 0; i < lis.length; ++i ) - { - try{ - var li = lis\[i\]; - if ( li.style.backgroundColor == "#ffee88" ) - { - alist = lis\[i\].getElementsByTagName("a") - if(alist.length > 0){ - location.href=alist\[0\].href; - } - } - }catch(err) { } - } - return - } - - if(event.keyCode == 38){ //Up arrow - var vars_ol = document.getElementById('vars'); - var lis = vars_ol.getElementsByTagName("li"); - for ( var i = 0; i < lis.length; ++i ) - { - try{ - var li = lis\[i\]; - if ( li.style.backgroundColor == "#ffee88" ) - { - if( (i-1) >= 0){ - var li_new = lis\[i-1\]; - li.style.backgroundColor = "white"; - li_new.style.backgroundColor = "#ffee88"; - return - } - } - }catch(err) { } - } - return - } - - if(event.keyCode == 40){ //Down arrow - var vars_ol = document.getElementById('vars'); - var lis = vars_ol.getElementsByTagName("li"); - for ( var i = 0; i < lis.length; ++i ) - { - try{ - var li = lis\[i\]; - if ( li.style.backgroundColor == "#ffee88" ) - { - if( (i+1) < lis.length){ - var li_new = lis\[i+1\]; - li.style.backgroundColor = "white"; - li_new.style.backgroundColor = "#ffee88"; - return - } - } - }catch(err) { } - } - return - } + var vars_ol = document.getElementById("vars"); //This part here resets everything to how it was at the start so the filter is applied to the complete list. Screw efficiency, it's client-side anyway and it only looks through 200 or so variables at maximum anyway (mobs). if(complete_list != null && complete_list != ""){ - var vars_ol1 = document.getElementById("vars"); - vars_ol1.innerHTML = complete_list + vars_ol.innerHTML = complete_list } - if(filter.value == ""){ + if(filter === ""){ return; }else{ - var vars_ol = document.getElementById('vars'); - var lis = vars_ol.getElementsByTagName("li"); - + var lis = Array.from(vars_ol.children); + var fragment = document.createDocumentFragment(); for ( var i = 0; i < lis.length; ++i ) { try{ var li = lis\[i\]; - if ( li.innerText.toLowerCase().indexOf(filter) == -1 ) + var text = li.textContent.toLowerCase(); + + var aElements = li.getElementsByTagName('a'); + for (var j = 0; j < aElements.length; j++) + { + var aText = aElements\[j\].textContent.trim().toLowerCase(); + if (aText === 'e' || aText === 'c' || aText === 'm') + { + text = text.replace(aElements\[j\].textContent.toLowerCase(), ''); + } + } + if ( text.indexOf(filter) !== -1 ) { - vars_ol.removeChild(li); - i--; + fragment.appendChild(li) } }catch(err) { } } - } - var lis_new = vars_ol.getElementsByTagName("li"); - for ( var j = 0; j < lis_new.length; ++j ) - { - var li1 = lis\[j\]; - if (j == 0){ - li1.style.backgroundColor = "#ffee88"; - }else{ - li1.style.backgroundColor = "white"; - } + + vars_ol.innerHTML = ''; + vars_ol.appendChild(fragment); } } - - function selectTextField(){ var filter_text = document.getElementById('filter'); filter_text.focus(); @@ -161,7 +100,7 @@ } "} - body += "" + body += "" body += "
" @@ -232,72 +171,72 @@ "} - body += "" + body += "" if(ismob(D)) - body += "" + body += "" if(istype(D, /atom/movable)) - body += "" + body += "" else var/atom/A = D if(istype(A)) - body += "" + body += "" body += "" if(ismob(D)) - body += "" - body += "" - body += "" + body += "" + body += "" + body += "" if(isliving(D)) - body += "" - body += "" - body += "" - body += "" + body += "" + body += "" + body += "" + body += "" - body += "" + body += "" - body += "" - body += "" + body += "" + body += "" - body += "" - body += "" - body += "" + body += "" + body += "" + body += "" if(ishuman(D) || istype(D, /mob/dead/new_player)) - body += "" + body += "" - body += "" - body += "" - body += "" + body += "" + body += "" + body += "" if(isAI(D)) body += "" - body += "" + body += "" if(ishuman(D)) body += "" - body += "" - body += "" - body += "" - body += "" - body += "" - body += "" - body += "" + body += "" + body += "" + body += "" + body += "" + body += "" + body += "" + body += "" body += "" - body += "" - body += "" + body += "" + body += "" if(isatom(D)) - body += "" - body += "" - body += "" - body += "" + body += "" + body += "" + body += "" + body += "" if(isobj(D)) - body += "" + body += "" if(isobj(D) || ismob(D) || isturf(D)) - body += "" - body += "" + body += "" + body += "" if(istype(D, /datum/reagents)) - body += "" - body += "" - body += "" - body += "" + body += "" + body += "" + body += "" + body += "" body += "" @@ -307,7 +246,7 @@ body += "C - Change, asks you for the var type first.
" body += "M - Mass modify: changes this variable for all objects of this type.
" - body += "
Search:

" + body += "
Search:

" body += "
    " @@ -324,7 +263,7 @@ body += "
" - var/html = "" + var/html = "" if (title) html += "[title]" html += {"