From 00e8bf1fc2c9a98baec988ee74fceccada2f0365 Mon Sep 17 00:00:00 2001 From: CodeKevin Date: Thu, 24 Sep 2015 23:56:46 -0400 Subject: [PATCH] Closes #53 Not sure where or if this fix will break but should suffice. --- CTFd/static/admin/js/chalboard.js | 16 ++++++++++++++-- CTFd/static/js/chalboard.js | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CTFd/static/admin/js/chalboard.js b/CTFd/static/admin/js/chalboard.js index 3f30690e..7c74d0ce 100644 --- a/CTFd/static/admin/js/chalboard.js +++ b/CTFd/static/admin/js/chalboard.js @@ -1,3 +1,15 @@ +//http://stackoverflow.com/a/7616484 +String.prototype.hashCode = function() { + var hash = 0, i, chr, len; + if (this.length == 0) return hash; + for (i = 0, len = this.length; i < len; i++) { + chr = this.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; + hash |= 0; // Convert to 32bit integer + } + return hash; +}; + function loadchal(id) { // $('#chal *').show() // $('#chal > h1').hide() @@ -130,7 +142,7 @@ function loadchals(){ for (var i = challenges['game'].length - 1; i >= 0; i--) { if ($.inArray(challenges['game'][i].category, categories) == -1) { categories.push(challenges['game'][i].category) - $('#challenges').append($('

' + challenges['game'][i].category + '

')) + $('#challenges').append($('

' + challenges['game'][i].category + '

')) } }; @@ -140,7 +152,7 @@ function loadchals(){ }; for (var i = 0; i <= challenges['game'].length - 1; i++) { - $('#' + challenges['game'][i].category.replace(/ /g,"-")).append($('')); + $('#' + challenges['game'][i].category.replace(/ /g,"-").hashCode()).append($('')); }; $('#challenges button').click(function (e) { diff --git a/CTFd/static/js/chalboard.js b/CTFd/static/js/chalboard.js index 90287e0c..1e14b330 100644 --- a/CTFd/static/js/chalboard.js +++ b/CTFd/static/js/chalboard.js @@ -13,6 +13,18 @@ function htmlentities(string) { return $('
').text(string).html(); } +//http://stackoverflow.com/a/7616484 +String.prototype.hashCode = function() { + var hash = 0, i, chr, len; + if (this.length == 0) return hash; + for (i = 0, len = this.length; i < len; i++) { + chr = this.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; + hash |= 0; // Convert to 32bit integer + } + return hash; +}; + var challenges; function loadchal(id) { @@ -189,12 +201,12 @@ function loadchals() { challenges['game'][i].solves = 0 if ($.inArray(challenges['game'][i].category, categories) == -1) { categories.push(challenges['game'][i].category) - $('#challenges').append($('

' + challenges['game'][i].category + '

')) + $('#challenges').append($('

' + challenges['game'][i].category + '

')) } }; for (var i = 0; i <= challenges['game'].length - 1; i++) { - $('#' + challenges['game'][i].category.replace(/ /g,"-")).append($('')); + $('#' + challenges['game'][i].category.replace(/ /g,"-").hashCode()).append($('')); }; updatesolves() marktoomanyattempts()