From 065eec5f22fe0d11a44cd4048fb2e4a1b036f5da Mon Sep 17 00:00:00 2001 From: Austin Date: Fri, 19 Nov 2021 00:42:49 -0500 Subject: [PATCH] alphaland JS html parser slight cleanup --- AlphalandUtilityJsSource.txt | 45 +++++++++++++++++----------------- globals/config.php | 2 +- html/alphaland/js/utilities.js | 12 ++++----- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/AlphalandUtilityJsSource.txt b/AlphalandUtilityJsSource.txt index d3624ca..7cb0e76 100644 --- a/AlphalandUtilityJsSource.txt +++ b/AlphalandUtilityJsSource.txt @@ -26,34 +26,35 @@ function parseHtml(html, limit, object, message, singleObject=false) { } for (var pos = 0; pos <= html.length; pos++) { - if (html.charAt(pos) == "{") { //first position + var firstFound = false; + var functionCall = false; + var secondPositionIdentifier = ""; + if (html.charAt(pos) == "{") { + firstFound = true; + secondPositionIdentifier = "}"; + } else if (html.charAt(pos) == "[") { + firstFound = true; + functionCall = true; + secondPositionIdentifier = "]"; + } + + if (firstFound) { //first position for (var len = pos; len; len++) { - if (html.charAt(len) == "}") { //second position + if (html.charAt(len) == secondPositionIdentifier) { var marker = ""; for (var d = pos; d < len+1; d++) { //data between the two positions marker += html.charAt(d); } - buffer = buffer.replace(marker, objectData[marker.substring(1, marker.length - 1)]); //using replace instead of replaceAll for compatibility - break; - } - } - } - else if (html.charAt(pos) == "[") { //first position - for (var len = pos; len; len++) { - if (html.charAt(len) == "]") { //second position - var marker = ""; - for (var d = pos; d < len+1; d++) { //data between the two positions - marker += html.charAt(d); - } - - var call = marker.substring(1, marker.length - 1); //grab the function name we wanna call - try { - call = window[call](objectData) //call the function with the object passed as a parameter - buffer = buffer.replace(marker, call); //replace the marker with the data returned from the call //using replace instead of replaceAll for compatibility - } - catch (error) { - //do nothing + if (!functionCall) { + buffer = buffer.replace(marker, objectData[marker.substring(1, marker.length - 1)]); //using replace instead of replaceAll for compatibility + } else { + try { + buffer = buffer.replace(marker, window[marker.substring(1, marker.length - 1)](objectData)); //replace the marker with the data returned from the call //using replace instead of replaceAll for compatibility + } + catch (error) { + //do nothing + } } break; } diff --git a/globals/config.php b/globals/config.php index 38360cc..d5a6b3a 100644 --- a/globals/config.php +++ b/globals/config.php @@ -25,7 +25,7 @@ try $pdo = new PDO("mysql:host=localhost;dbname=alphalanddatabase", "aa9205c5b776b2368833bec1e8b34e1c", "68adae776e087fb1b34baf439710cf94", $pdoOptions); //general vars - $jsversion = "3.04"; //update this after updating JS, this will re-cache the latest js for users + $jsversion = "3.07"; //update this after updating JS, this will re-cache the latest js for users $cssversion = "3.02"; //update this after updating CSS, this will re-cache the latest css for users $siteName = "Alphaland"; //site name diff --git a/html/alphaland/js/utilities.js b/html/alphaland/js/utilities.js index e843957..23f7358 100644 --- a/html/alphaland/js/utilities.js +++ b/html/alphaland/js/utilities.js @@ -1,9 +1,9 @@ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b'),$(c).html(b));getJSONCDS(a+"?limit="+l+"&page="+p+"&keyword="+m+n).done(function(g){$(c).html(parseHtml(f,l,g,d))})} -function multiPageHelper(a,b,c,f,p,l,m,d,n,g,e,h){h=void 0===h?"":h;""!==f&&(f='
'),$(p).html(f));var k="";b&&b.constructor===Array&&(k=parseArrayArgs(b));$(l).html("");getJSONCDS(c+"?limit="+n+"&page="+d+"&keyword="+g+h).done(function(u){var r=!1,t="",q=u.pageCount,y=u.pageResults,w=d+1,v=d-1;var x=d+3;w>q&&(w=q);0==v&&(v=1);1q?(r=1,x=q):v==d-1?(r=d>=q-2?q-3:d-1,--x):r=d;t+='';t+='';for(i=r;i<=x;i++)i<=q&&(t+='");t+='';t+=''}$(p).html(parseHtml(m, -y,u,e));$(l).html(t)})}var Comments=function(a,b,c,f,p,l,m,d,n){this.assetid=a;this.commentsid=b;this.commentscontainer=c;this.buttonscontainer=f;this.successid=p;this.errorid=l;this.inputid=m;this.messageDelay=d;this.newObject=n;var g=this;getJSONCDS("https://api.alphaland.cc/game/info?id="+this.assetid).done(function(e){e.CommentsEnabled&&($(g.commentsid).show(),g.commentsPage())})}; +function parseHtml(a,b,c,f,n){n=void 0===n?!1:n;for(var h="",k,e=0;e'),$(c).html(b));getJSONCDS(a+"?limit="+h+"&page="+n+"&keyword="+k+l).done(function(g){$(c).html(parseHtml(f,h,g,e))})} +function multiPageHelper(a,b,c,f,n,h,k,e,l,g,m,q){q=void 0===q?"":q;""!==f&&(f='
'),$(n).html(f));var d="";b&&b.constructor===Array&&(d=parseArrayArgs(b));$(h).html("");getJSONCDS(c+"?limit="+l+"&page="+e+"&keyword="+g+q).done(function(r){var t=!1,u="",p=r.pageCount,y=r.pageResults,w=e+1,v=e-1;var x=e+3;w>p&&(w=p);0==v&&(v=1);1p?(t=1,x=p):v==e-1?(t=e>=p-2?p-3:e-1,--x):t=e;u+='';u+='';for(i=t;i<=x;i++)i<=p&&(u+='");u+='';u+=''}$(n).html(parseHtml(k, +y,r,m));$(h).html(u)})}var Comments=function(a,b,c,f,n,h,k,e,l){this.assetid=a;this.commentsid=b;this.commentscontainer=c;this.buttonscontainer=f;this.successid=n;this.errorid=h;this.inputid=k;this.messageDelay=e;this.newObject=l;var g=this;getJSONCDS("https://api.alphaland.cc/game/info?id="+this.assetid).done(function(m){m.CommentsEnabled&&($(g.commentsid).show(),g.commentsPage())})}; Comments.prototype.commentsPage=function(a){multiPageHelper(this.newObject+".commentsPage",[],"https://api.alphaland.cc/comments/","https://api.alphaland.cc/logo",this.commentscontainer,this.buttonscontainer,'
Comment by {username} : {date}

{comment}

', void 0===a?1:a,10,"","No comments","&assetId="+this.assetid)};Comments.prototype.submitComment=function(a){var b=this;postJSONCDS("https://api.alphaland.cc/comments/newcomment?assetId="+this.assetid,JSON.stringify({comment:a})).done(function(c){c=c.alert;var f=b.errorid;"Comment Placed"==c&&(f=b.successid,$(b.inputid).val(""),b.commentsPage());$(f).text(c);$(f).show();window.scrollTo({top:0,behavior:"smooth"});setTimeout(function(){$(f).hide()},b.messageDelay)})}; \ No newline at end of file