electrikjesus | b84b56e | 2017-04-28 13:31:09 -0400 | [diff] [blame] | 1 | // JavaScript Document |
| 2 | $(document).ready(function(e) { |
| 3 | /* Todo: |
| 4 | • Merge this with Node.js, almost done |
| 5 | • Webpages in a database/more editable version |
| 6 | • Add cookies to track previous commands? (You can press up and down to browse previous commands this session) |
| 7 | */ |
| 8 | var faviconnumber = 1; |
| 9 | function favicon() { |
| 10 | favicon = favicon == 1 ? 2 : 1; |
| 11 | $('.favicon').attr('href','favicon' + favicon + ".png"); |
| 12 | } |
| 13 | console.clear(); |
| 14 | var commandlist = [ /*Can be populated with various methods*/ |
| 15 | ["/help", "Show commands"], |
| 16 | ["/list", "List all pages on the website"], |
| 17 | ["/nav <location>", "Navigate to location"], |
electrikjesus | 7f54eef | 2017-04-28 16:13:01 -0400 | [diff] [blame] | 18 | ["/gl", "Generate a url for the current page - [^http://blissroms.github.io/](This doesn't work in an iFrame.) outputs something like [^http://blissroms.github.io/connect](*blissroms.io/connect*)"], |
electrikjesus | b84b56e | 2017-04-28 13:31:09 -0400 | [diff] [blame] | 19 | ["/clear", "Clear the console"], |
| 20 | ["/login <username> <password>", "Login to your account - This is not set up and when implemeneted it'll be '/login username' then request password without printing into the cmd prompt"], |
| 21 | ["/upload", "Upload file, must be logged in."] |
| 22 | ]; |
| 23 | var previouscommands = []; |
| 24 | var currentcommand = 0; |
| 25 | var pages = [ /*Can be populated with various methods*/ |
electrikjesus | 8de5001 | 2017-04-28 16:02:13 -0400 | [diff] [blame] | 26 | ["index", "Welcome to BlissROMs temporary site", "This is a temporary website we are puting up in order to help with the current transition of our website", "You can find us online or on Telegram using the following links.", "Google+: [https://plus.google.com/communities/118265887490106132524](https://plus.google.com/communities/118265887490106132524)","Telegram: [https://t.me/OfficialBlissROMs](https://t.me/OfficialBlissROMs)"], |
| 27 | ["about", "About Bliss", "A little info about us", "We are a family of ROMs, app developers, designers, and tech gurus, that work together to bring our dreams to life.", "To join Bliss Family of ROMs, [https://goo.gl/ZJn2vn](https://goo.gl/ZJn2vn)", "We are currently accepting applications for developers, maintainers, app devs, designers, and marketing/PR."], |
| 28 | ["connect", "Connect with Bliss", |
| 29 | "[mailto:Officialblissroms@gmail.com](Email Bliss)", |
| 30 | "[^https://plus.google.com/communities/118265887490106132524](Google+ Community)", |
electrikjesus | 06662a6 | 2017-04-28 16:05:50 -0400 | [diff] [blame] | 31 | "[^https://t.me/OfficialBlissROMs](Telegram Community)", |
electrikjesus | 8de5001 | 2017-04-28 16:02:13 -0400 | [diff] [blame] | 32 | "[^https://review.blissroms.com](Gerrit Code Review for Blissroms)"] |
electrikjesus | b84b56e | 2017-04-28 13:31:09 -0400 | [diff] [blame] | 33 | ]; |
| 34 | var pageindex = ["index", "about", "connect"]; |
| 35 | var currentpage = "landing"; |
electrikjesus | 8de5001 | 2017-04-28 16:02:13 -0400 | [diff] [blame] | 36 | var url = "http://blissroms.github.io/" |
electrikjesus | b84b56e | 2017-04-28 13:31:09 -0400 | [diff] [blame] | 37 | /* |
| 38 | Custom Text Syntax |
| 39 | Links: |
| 40 | [URLPATH](NAME) - regular |
| 41 | [^URLPATH](NAME) - open in new tab |
| 42 | |
| 43 | Styles: |
| 44 | *TEXT* - bold text |
| 45 | E! - Text is an error/notification |
| 46 | A! - spaces are converted to non-breaking spaces (it's for ascii art - after all, this is a text based website) |
| 47 | */ |
| 48 | |
| 49 | function init() { |
| 50 | setInterval(time); |
| 51 | console.clear(); |
| 52 | console.log(new Date().getTime()); |
| 53 | log("Website", "A!********************************"); |
| 54 | log("Website", "A!* ____ _ ___ ____ ____ *"); |
| 55 | log("Website", "A!* | __ )| | |_ _/ ___/ ___| *"); |
electrikjesus | 9acfadc | 2017-04-28 17:15:44 -0400 | [diff] [blame^] | 56 | log("Website", "A!* | _ | | | | ||___ |___ | *"); |
electrikjesus | b84b56e | 2017-04-28 13:31:09 -0400 | [diff] [blame] | 57 | log("Website", "A!* | |_) | |___ | | ___) |__) | *"); |
| 58 | log("Website", "A!* |____/|_____|___|____/____/ *"); |
| 59 | log("Website", "A!* *"); |
| 60 | log("Website", "A!********************************"); |
| 61 | log("Website", "A!Have A Truly Blissful Experience"); |
| 62 | log("Website", "A!********************************"); |
| 63 | log("Website", ""); |
electrikjesus | 9acfadc | 2017-04-28 17:15:44 -0400 | [diff] [blame^] | 64 | log("Website", "E!Bliss ROMs temporary site [^http://blissroms.github.io/](*blissroms.github.io*)"); |
electrikjesus | b84b56e | 2017-04-28 13:31:09 -0400 | [diff] [blame] | 65 | log("Website", ""); |
| 66 | log("Website", "A!********************************"); |
| 67 | log("Website", ""); |
electrikjesus | 430554b | 2017-04-28 16:21:07 -0400 | [diff] [blame] | 68 | log("Website", "E , [^http://paypal.me/TeamBliss](*Donate to Team Bliss*)"); |
| 69 | log("Website", "E"); |
| 70 | |
| 71 | urlvars(); |
electrikjesus | b84b56e | 2017-04-28 13:31:09 -0400 | [diff] [blame] | 72 | log("Client", "For help say '/help'"); |
| 73 | setInterval(favicon,500); |
| 74 | } |
| 75 | |
| 76 | function urlvars() { |
| 77 | var pagelocs = window.location.pathname.replace("/","").split("/"); |
| 78 | var pageloc = pagelocs[0]; |
| 79 | console.log(pageloc); |
| 80 | //alert(); |
| 81 | if(pageloc != "") { |
| 82 | if ($.inArray(pageloc, pageindex) >= 0) { |
| 83 | currentpage = pageloc; |
| 84 | } |
| 85 | } |
| 86 | log("Website", "You are currently on page: *" + currentpage + "*"); |
| 87 | if(pageloc != "") { |
| 88 | if ($.inArray(pageloc, pageindex) >= 0) { |
| 89 | currentpage = pageloc; |
| 90 | loadpage($.inArray(pageloc, pageindex)); |
| 91 | } else { |
| 92 | //Un-note next line to show 404 errors with wrong urls |
| 93 | //log("Client", "404 - The page '" + pageloc + "' does not exist. To "); |
| 94 | } |
| 95 | } |
| 96 | if(pageloc == "") { |
| 97 | log("Client", "What would you like to access?"); |
| 98 | } |
| 99 | } |
| 100 | function getParam(name){ |
| 101 | name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); |
| 102 | var regexS = "[\\?&]"+name+"=([^&#]*)"; |
| 103 | var regex = new RegExp( regexS ); |
| 104 | var results = regex.exec (window.location.href); |
| 105 | if (results == null) { |
| 106 | return ""; |
| 107 | } |
| 108 | else { |
| 109 | return results[1]; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | function log(name, information) { |
| 114 | var d = new Date(); |
| 115 | var hours = ((d.getHours() < 10) ? "0" : "") + d.getHours(); |
| 116 | var minutes = ((d.getMinutes() < 10) ? "0" : "") + d.getMinutes(); |
| 117 | var seconds = ((d.getSeconds() < 10) ? "0" : "") + d.getSeconds(); |
| 118 | var colour = "whitet"; |
| 119 | var textcolour = ""; |
| 120 | var postcolour = ""; |
| 121 | |
| 122 | switch (name[0]) { |
| 123 | case "!": |
| 124 | postcolour = " important"; |
| 125 | name = name.substr(1); |
| 126 | break; |
| 127 | } |
| 128 | switch (name) { |
| 129 | case "Website": |
| 130 | colour = "redt"; |
| 131 | break; |
| 132 | case "Server": |
| 133 | colour = "bluet"; |
| 134 | break; |
| 135 | case "Client": |
| 136 | colour = "bluet"; |
| 137 | break; |
| 138 | case "User": |
| 139 | colour = "greent"; |
| 140 | postcolour = " selft"; |
| 141 | break; |
| 142 | } |
| 143 | if (information[0] == "A" && information[1] == "!") { |
| 144 | information = information.substr(2); |
| 145 | information = information.replace(/ /g, '\u00A0'); |
| 146 | } |
| 147 | if (information[0] == "E" && information[1] == "!") { |
| 148 | information = information.substr(2); |
| 149 | postcolour = " important"; |
| 150 | } |
| 151 | |
| 152 | while (information.indexOf("](") >= 0) { //URL parser |
| 153 | |
| 154 | var NAMEregExp = /\(([^)]+)\)/; |
| 155 | var uname = NAMEregExp.exec(information)[1]; |
| 156 | |
| 157 | var URLregExp = /\[([^)]+)\]/; |
| 158 | var url = URLregExp.exec(information)[1]; |
| 159 | var newpage = false; |
| 160 | if (url[0] == "^") { |
| 161 | newpage = true; |
| 162 | url = url.substr(1); |
| 163 | } |
| 164 | var start = information.indexOf("["); |
| 165 | var end = information.indexOf(")"); |
| 166 | if (newpage) { |
| 167 | information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '" target="_blank">' + uname + '</a>'); |
| 168 | } else { |
| 169 | information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '">' + uname + '</a>'); |
| 170 | } |
| 171 | //information = '<a href="' + url + '">' + uname + '</a>'; //working |
| 172 | |
| 173 | } |
| 174 | var tobold = true; |
| 175 | var boldnumber = 0; |
| 176 | for (var i = 0; i < information.length; i++) { |
| 177 | if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") { |
| 178 | boldnumber++; |
| 179 | } |
| 180 | } |
| 181 | while (information.indexOf("*") >= 0) { //Bold parser |
| 182 | var pos = information.indexOf("*"); |
| 183 | information = information.replace("*", ""); |
| 184 | if (tobold) { |
| 185 | information = information.splice(pos, 0, '<b>'); |
| 186 | } else { |
| 187 | information = information.splice(pos, 0, '</b>'); |
| 188 | } |
| 189 | tobold = !tobold; |
| 190 | if (tobold && boldnumber <= 1) { |
| 191 | break; |
| 192 | } |
| 193 | //information = '<a href="' + url + '">' + uname + '</a>'; //working |
| 194 | } |
| 195 | var tounderline = true; |
| 196 | var underlinenumber = 0; |
| 197 | for (var i = 0; i < information.length; i++) { |
| 198 | if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") { |
| 199 | underlinenumber++; |
| 200 | } |
| 201 | } |
| 202 | while (information.indexOf("**") >= 0) { //Bold parser |
| 203 | var pos = information.indexOf("**"); |
| 204 | information = information.replace("**", ""); |
| 205 | if (tounderline) { |
| 206 | information = information.splice(pos, 0, '<u>'); |
| 207 | } else { |
| 208 | information = information.splice(pos, 0, '</u>'); |
| 209 | } |
| 210 | tounderline = !tounderline; |
| 211 | if (tounderline && underlinenumber <= 1) { |
| 212 | break; |
| 213 | } |
| 214 | //information = '<a href="' + url + '">' + uname + '</a>'; //working |
| 215 | } /**/ |
| 216 | $(".stream").append('<div class="line">' + |
| 217 | '<p class="time">[' + hours + ":" + minutes + ":" + seconds + ']</p>' + |
| 218 | '<p class="name ' + colour + '">' + name + '</p>' + |
| 219 | '<p class="information' + postcolour + '">' + information + '</p>' + |
| 220 | '</div>'); |
| 221 | $(document).scrollTop($(document).height() - $(window).height()); |
| 222 | } |
| 223 | var timestring = ""; |
| 224 | function time() { |
| 225 | var d = new Date(); |
| 226 | var hours = d.getHours(); |
| 227 | var minutes = d.getMinutes(); |
| 228 | var seconds = d.getSeconds(); |
| 229 | if (hours < 10) { |
| 230 | hours = "0" + hours; |
| 231 | } |
| 232 | if (minutes < 10) { |
| 233 | minutes = "0" + minutes; |
| 234 | } |
| 235 | if (seconds < 10) { |
| 236 | seconds = "0" + seconds; |
| 237 | } |
| 238 | var temptimestring = "[" + hours + ":" + minutes + ":" + seconds + "]"; |
| 239 | if (temptimestring != timestring) { |
| 240 | timestring = temptimestring; |
| 241 | $(".editline .time").text(timestring); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | var ctrldown = false; |
| 246 | $(".editline .edit").keydown(function(e) { |
| 247 | var text = $(".editline .edit").text(); |
| 248 | console.log(e.which); |
| 249 | if (e.which == 13 && text !== "" && !ctrldown) { |
| 250 | var commands = text.split(' '); |
| 251 | var output = ""; |
| 252 | if (commands[0] == "help") { |
| 253 | text = "/" + text; |
| 254 | } |
| 255 | $(".editline .edit").text(""); |
| 256 | log("User", text); |
| 257 | |
| 258 | previouscommands[currentcommand] = text; |
| 259 | currentcommand = previouscommands.length; |
| 260 | $(".editline .edit").keydown(35); |
| 261 | cmd(commands[0], text, commands); |
| 262 | /*Add mod commands*/ |
| 263 | //modcmd(commands[0], text, commands); |
| 264 | /*Add mod commands*/ |
| 265 | |
| 266 | } |
| 267 | if (e.which == 38) { //up |
| 268 | if (currentcommand > 0) { |
| 269 | currentcommand--; |
| 270 | $(".editline .edit").text(previouscommands[currentcommand]); |
| 271 | } |
| 272 | } |
| 273 | if (e.which == 40) { //down |
| 274 | |
| 275 | if (currentcommand < previouscommands.length) { |
| 276 | currentcommand++; |
| 277 | $(".editline .edit").text(previouscommands[currentcommand]); |
| 278 | } |
| 279 | } |
| 280 | }); |
| 281 | |
| 282 | function cmd(command, words, word) { |
| 283 | switch (word[0]) { |
| 284 | case "/help": |
| 285 | case "help": |
| 286 | for (var i = 0; i < commandlist.length; i++) { |
| 287 | output = commandlist[i][0] + " : " + commandlist[i][1]; |
| 288 | //console.log(command[i][0]); |
| 289 | log("Client", output); |
| 290 | } |
| 291 | break; |
| 292 | case "/gl": |
| 293 | //window.location.href = "http://koya.io" + (currentpage == "landing" ? "" : "/" + currentpage); |
| 294 | window.history.pushState(currentpage, 'InpagePage', (currentpage == "landing" ? "/" : "/" + currentpage)); |
| 295 | break; |
| 296 | case "/clear": |
| 297 | $(".stream").text(""); |
| 298 | break; |
| 299 | case "/nav": |
| 300 | if ($.inArray(word[1], pageindex) >= 0) { |
| 301 | currentpage = word[1]; |
| 302 | log("Website", "You are now in " + currentpage); |
| 303 | loadpage($.inArray(word[1], pageindex)); |
| 304 | } else { |
| 305 | log("Client", "'" + word[1] + "' does not exist."); |
| 306 | } |
| 307 | break; |
| 308 | case "/list": |
| 309 | $.each(pageindex, function(id, content) { |
| 310 | log("Client", "> " + content); |
| 311 | }); |
| 312 | break; |
| 313 | case "/login": |
| 314 | if (word.length >= 3) { |
| 315 | log("Client", "Attempting to login to " + word[1] + " with " + Array(word[2].length + 1).join("•")); |
| 316 | loginreturn = false; |
| 317 | //log("Client", "ER1"); |
| 318 | setTimeout(loginemptyreturn, 20000); |
| 319 | } else { |
| 320 | log("Client", "Not enough arguments to log in, you need a USERNAME and a PASSWORD."); |
| 321 | } |
| 322 | break; |
| 323 | default: |
| 324 | output = "Unrecognised command '" + word[0] + "'."; |
| 325 | log("Client", output); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | function loadpage(i) { |
| 330 | $.each(pages[i], function(id, content) { |
| 331 | if (content != pageindex[i]) { |
| 332 | log("Website", content); |
| 333 | } |
| 334 | }); |
| 335 | } |
| 336 | var loginreturn = false; |
| 337 | |
| 338 | function loginemptyreturn() { |
| 339 | //log("Client", "ER2"); |
| 340 | if (!loginreturn) { |
| 341 | log("Client", "E![LOGIN] No Return Recieved"); |
| 342 | } |
| 343 | } |
| 344 | String.prototype.splice = function(idx, rem, str) { |
| 345 | return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem)); |
| 346 | }; |
| 347 | init(); |
| 348 | }); |