blob: a079bcf6d0af4d2b91a6eba4bc7dc254738f24ce [file] [log] [blame]
electrikjesusb84b56e2017-04-28 13:31:09 -04001// 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"],
electrikjesus300757b2017-04-28 18:07:01 -040018 ["/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.github.io/connect*)"],
electrikjesusb84b56e2017-04-28 13:31:09 -040019 ["/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*/
electrikjesus8de50012017-04-28 16:02:13 -040026 ["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)",
electrikjesus06662a62017-04-28 16:05:50 -040031 "[^https://t.me/OfficialBlissROMs](Telegram Community)",
electrikjesus8de50012017-04-28 16:02:13 -040032 "[^https://review.blissroms.com](Gerrit Code Review for Blissroms)"]
electrikjesusb84b56e2017-04-28 13:31:09 -040033 ];
34 var pageindex = ["index", "about", "connect"];
35 var currentpage = "landing";
electrikjesus8de50012017-04-28 16:02:13 -040036 var url = "http://blissroms.github.io/"
electrikjesusb84b56e2017-04-28 13:31:09 -040037 /*
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!* | __ )| | |_ _/ ___/ ___| *");
electrikjesusaf32c2c2017-04-28 18:03:33 -040056 log("Website", "A!* | _) | | | |(___ (___ ) *");
electrikjesusb84b56e2017-04-28 13:31:09 -040057 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", "");
electrikjesus9acfadc2017-04-28 17:15:44 -040064 log("Website", "E!Bliss ROMs temporary site [^http://blissroms.github.io/](*blissroms.github.io*)");
electrikjesusb84b56e2017-04-28 13:31:09 -040065 log("Website", "");
66 log("Website", "A!********************************");
67 log("Website", "");
electrikjesus430554b2017-04-28 16:21:07 -040068 log("Website", "E![^http://downloads.blissroms.com/](*Bliss Downloads*) , [^http://paypal.me/TeamBliss](*Donate to Team Bliss*)");
69 log("Website", "E![^http://review.blissroms.com](*BlissROMs Gerrit Review*)");
electrikjesus2c4c1192017-04-28 18:08:46 -040070 log("Website", "");
71 log("Website", "A!********************************");
electrikjesus430554b2017-04-28 16:21:07 -040072 urlvars();
electrikjesusb84b56e2017-04-28 13:31:09 -040073 log("Client", "For help say '/help'");
74 setInterval(favicon,500);
75 }
76
77 function urlvars() {
78 var pagelocs = window.location.pathname.replace("/","").split("/");
79 var pageloc = pagelocs[0];
80 console.log(pageloc);
81 //alert();
82 if(pageloc != "") {
83 if ($.inArray(pageloc, pageindex) >= 0) {
84 currentpage = pageloc;
85 }
86 }
87 log("Website", "You are currently on page: *" + currentpage + "*");
88 if(pageloc != "") {
89 if ($.inArray(pageloc, pageindex) >= 0) {
90 currentpage = pageloc;
91 loadpage($.inArray(pageloc, pageindex));
92 } else {
93 //Un-note next line to show 404 errors with wrong urls
94 //log("Client", "404 - The page '" + pageloc + "' does not exist. To ");
95 }
96 }
97 if(pageloc == "") {
98 log("Client", "What would you like to access?");
99 }
100 }
101 function getParam(name){
102 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
103 var regexS = "[\\?&]"+name+"=([^&#]*)";
104 var regex = new RegExp( regexS );
105 var results = regex.exec (window.location.href);
106 if (results == null) {
107 return "";
108 }
109 else {
110 return results[1];
111 }
112 }
113
114 function log(name, information) {
115 var d = new Date();
116 var hours = ((d.getHours() < 10) ? "0" : "") + d.getHours();
117 var minutes = ((d.getMinutes() < 10) ? "0" : "") + d.getMinutes();
118 var seconds = ((d.getSeconds() < 10) ? "0" : "") + d.getSeconds();
119 var colour = "whitet";
120 var textcolour = "";
121 var postcolour = "";
122
123 switch (name[0]) {
124 case "!":
125 postcolour = " important";
126 name = name.substr(1);
127 break;
128 }
129 switch (name) {
130 case "Website":
131 colour = "redt";
132 break;
133 case "Server":
134 colour = "bluet";
135 break;
136 case "Client":
137 colour = "bluet";
138 break;
139 case "User":
140 colour = "greent";
141 postcolour = " selft";
142 break;
143 }
144 if (information[0] == "A" && information[1] == "!") {
145 information = information.substr(2);
146 information = information.replace(/ /g, '\u00A0');
147 }
148 if (information[0] == "E" && information[1] == "!") {
149 information = information.substr(2);
150 postcolour = " important";
151 }
152
153 while (information.indexOf("](") >= 0) { //URL parser
154
155 var NAMEregExp = /\(([^)]+)\)/;
156 var uname = NAMEregExp.exec(information)[1];
157
158 var URLregExp = /\[([^)]+)\]/;
159 var url = URLregExp.exec(information)[1];
160 var newpage = false;
161 if (url[0] == "^") {
162 newpage = true;
163 url = url.substr(1);
164 }
165 var start = information.indexOf("[");
166 var end = information.indexOf(")");
167 if (newpage) {
168 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '" target="_blank">' + uname + '</a>');
169 } else {
170 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '">' + uname + '</a>');
171 }
172 //information = '<a href="' + url + '">' + uname + '</a>'; //working
173
174 }
175 var tobold = true;
176 var boldnumber = 0;
177 for (var i = 0; i < information.length; i++) {
178 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
179 boldnumber++;
180 }
181 }
182 while (information.indexOf("*") >= 0) { //Bold parser
183 var pos = information.indexOf("*");
184 information = information.replace("*", "");
185 if (tobold) {
186 information = information.splice(pos, 0, '<b>');
187 } else {
188 information = information.splice(pos, 0, '</b>');
189 }
190 tobold = !tobold;
191 if (tobold && boldnumber <= 1) {
192 break;
193 }
194 //information = '<a href="' + url + '">' + uname + '</a>'; //working
195 }
196 var tounderline = true;
197 var underlinenumber = 0;
198 for (var i = 0; i < information.length; i++) {
199 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
200 underlinenumber++;
201 }
202 }
203 while (information.indexOf("**") >= 0) { //Bold parser
204 var pos = information.indexOf("**");
205 information = information.replace("**", "");
206 if (tounderline) {
207 information = information.splice(pos, 0, '<u>');
208 } else {
209 information = information.splice(pos, 0, '</u>');
210 }
211 tounderline = !tounderline;
212 if (tounderline && underlinenumber <= 1) {
213 break;
214 }
215 //information = '<a href="' + url + '">' + uname + '</a>'; //working
216 } /**/
217 $(".stream").append('<div class="line">' +
218 '<p class="time">[' + hours + ":" + minutes + ":" + seconds + ']</p>' +
219 '<p class="name ' + colour + '">' + name + '</p>' +
220 '<p class="information' + postcolour + '">' + information + '</p>' +
221 '</div>');
222 $(document).scrollTop($(document).height() - $(window).height());
223 }
224 var timestring = "";
225 function time() {
226 var d = new Date();
227 var hours = d.getHours();
228 var minutes = d.getMinutes();
229 var seconds = d.getSeconds();
230 if (hours < 10) {
231 hours = "0" + hours;
232 }
233 if (minutes < 10) {
234 minutes = "0" + minutes;
235 }
236 if (seconds < 10) {
237 seconds = "0" + seconds;
238 }
239 var temptimestring = "[" + hours + ":" + minutes + ":" + seconds + "]";
240 if (temptimestring != timestring) {
241 timestring = temptimestring;
242 $(".editline .time").text(timestring);
243 }
244 }
245
246 var ctrldown = false;
247 $(".editline .edit").keydown(function(e) {
248 var text = $(".editline .edit").text();
249 console.log(e.which);
250 if (e.which == 13 && text !== "" && !ctrldown) {
251 var commands = text.split(' ');
252 var output = "";
253 if (commands[0] == "help") {
254 text = "/" + text;
255 }
256 $(".editline .edit").text("");
257 log("User", text);
258
259 previouscommands[currentcommand] = text;
260 currentcommand = previouscommands.length;
261 $(".editline .edit").keydown(35);
262 cmd(commands[0], text, commands);
263 /*Add mod commands*/
264 //modcmd(commands[0], text, commands);
265 /*Add mod commands*/
266
267 }
268 if (e.which == 38) { //up
269 if (currentcommand > 0) {
270 currentcommand--;
271 $(".editline .edit").text(previouscommands[currentcommand]);
272 }
273 }
274 if (e.which == 40) { //down
275
276 if (currentcommand < previouscommands.length) {
277 currentcommand++;
278 $(".editline .edit").text(previouscommands[currentcommand]);
279 }
280 }
281 });
282
283 function cmd(command, words, word) {
284 switch (word[0]) {
285 case "/help":
286 case "help":
287 for (var i = 0; i < commandlist.length; i++) {
288 output = commandlist[i][0] + " : " + commandlist[i][1];
289 //console.log(command[i][0]);
290 log("Client", output);
291 }
292 break;
293 case "/gl":
294 //window.location.href = "http://koya.io" + (currentpage == "landing" ? "" : "/" + currentpage);
295 window.history.pushState(currentpage, 'InpagePage', (currentpage == "landing" ? "/" : "/" + currentpage));
296 break;
297 case "/clear":
298 $(".stream").text("");
299 break;
300 case "/nav":
301 if ($.inArray(word[1], pageindex) >= 0) {
302 currentpage = word[1];
303 log("Website", "You are now in " + currentpage);
304 loadpage($.inArray(word[1], pageindex));
305 } else {
306 log("Client", "'" + word[1] + "' does not exist.");
307 }
308 break;
309 case "/list":
310 $.each(pageindex, function(id, content) {
311 log("Client", "> " + content);
312 });
313 break;
314 case "/login":
315 if (word.length >= 3) {
316 log("Client", "Attempting to login to " + word[1] + " with " + Array(word[2].length + 1).join("•"));
317 loginreturn = false;
318 //log("Client", "ER1");
319 setTimeout(loginemptyreturn, 20000);
320 } else {
321 log("Client", "Not enough arguments to log in, you need a USERNAME and a PASSWORD.");
322 }
323 break;
324 default:
325 output = "Unrecognised command '" + word[0] + "'.";
326 log("Client", output);
327 }
328 }
329
330 function loadpage(i) {
331 $.each(pages[i], function(id, content) {
332 if (content != pageindex[i]) {
333 log("Website", content);
334 }
335 });
336 }
337 var loginreturn = false;
338
339 function loginemptyreturn() {
340 //log("Client", "ER2");
341 if (!loginreturn) {
342 log("Client", "E![LOGIN] No Return Recieved");
343 }
344 }
345 String.prototype.splice = function(idx, rem, str) {
346 return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
347 };
348 init();
349});