blob: 82cf1e8198ee5a69cf05a9eba71f49d841c32cc1 [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"],
electrikjesus48c3b7e2017-04-28 21:45:48 -040018 ["/gl", "Generate a url for the current page - not currently working"],
electrikjesusb84b56e2017-04-28 13:31:09 -040019 ["/clear", "Clear the console"],
electrikjesusb27a2f32017-04-28 22:04:41 -040020 ["brunch + bliss_device", "Initiate device compile - Example: 'brunch bliss_bacon' will get you a build for bacon, 'brunch bliss_x86' will get you a build for Bliss-x86. You get the idea"],
electrikjesusb84b56e2017-04-28 13:31:09 -040021 ["/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"],
22 ["/upload", "Upload file, must be logged in."]
23 ];
24 var previouscommands = [];
25 var currentcommand = 0;
26 var pages = [ /*Can be populated with various methods*/
electrikjesus8de50012017-04-28 16:02:13 -040027 ["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)"],
28 ["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."],
29 ["connect", "Connect with Bliss",
30 "[mailto:Officialblissroms@gmail.com](Email Bliss)",
31 "[^https://plus.google.com/communities/118265887490106132524](Google+ Community)",
electrikjesus06662a62017-04-28 16:05:50 -040032 "[^https://t.me/OfficialBlissROMs](Telegram Community)",
electrikjesus48301812017-05-07 14:11:12 -040033 "[^https://review.blissroms.com](Gerrit Code Review for Blissroms)"
34 "[^https://goo.gl/forms/PdiaAj1PojosmehK2](*Join Team Bliss*)"]
electrikjesusb84b56e2017-04-28 13:31:09 -040035 ];
36 var pageindex = ["index", "about", "connect"];
37 var currentpage = "landing";
electrikjesus8de50012017-04-28 16:02:13 -040038 var url = "http://blissroms.github.io/"
electrikjesusb84b56e2017-04-28 13:31:09 -040039 /*
40 Custom Text Syntax
41 Links:
42 [URLPATH](NAME) - regular
43 [^URLPATH](NAME) - open in new tab
44
45 Styles:
46 *TEXT* - bold text
47 E! - Text is an error/notification
48 A! - spaces are converted to non-breaking spaces (it's for ascii art - after all, this is a text based website)
49 */
50
51 function init() {
52 setInterval(time);
53 console.clear();
54 console.log(new Date().getTime());
electrikjesus5220b0e2017-04-28 18:27:50 -040055 log("Website", "A!****************************");
56 log("Website", "A! ____ _ ___ ____ ____ ");
57 log("Website", "A!| __ )| | |_ _/ ___/ ___| ");
58 log("Website", "A!| _) | | | |(___ (___ ) ");
59 log("Website", "A!| |_) | |___ | | ___) |__) |");
60 log("Website", "A!|____/|_____|___|____/____/ ");
61 log("Website", "A! *");
62 log("Website", "A!****************************");
electrikjesusb84b56e2017-04-28 13:31:09 -040063 log("Website", "A!Have A Truly Blissful Experience");
electrikjesus5220b0e2017-04-28 18:27:50 -040064 log("Website", "A!****************************");
electrikjesusb84b56e2017-04-28 13:31:09 -040065 log("Website", "");
electrikjesus9acfadc2017-04-28 17:15:44 -040066 log("Website", "E!Bliss ROMs temporary site [^http://blissroms.github.io/](*blissroms.github.io*)");
electrikjesusb84b56e2017-04-28 13:31:09 -040067 log("Website", "");
68 log("Website", "A!********************************");
69 log("Website", "");
electrikjesus430554b2017-04-28 16:21:07 -040070 log("Website", "E![^http://downloads.blissroms.com/](*Bliss Downloads*) , [^http://paypal.me/TeamBliss](*Donate to Team Bliss*)");
electrikjesus2a277a52017-05-07 14:09:10 -040071 log("Website", "E![^http://review.blissroms.com](*BlissROMs Gerrit Review*) , [^https://goo.gl/forms/PdiaAj1PojosmehK2](*Join Team Bliss*)");
electrikjesus2c4c1192017-04-28 18:08:46 -040072 log("Website", "");
73 log("Website", "A!********************************");
electrikjesus430554b2017-04-28 16:21:07 -040074 urlvars();
electrikjesusb84b56e2017-04-28 13:31:09 -040075 log("Client", "For help say '/help'");
76 setInterval(favicon,500);
77 }
78
79 function urlvars() {
80 var pagelocs = window.location.pathname.replace("/","").split("/");
81 var pageloc = pagelocs[0];
82 console.log(pageloc);
83 //alert();
84 if(pageloc != "") {
85 if ($.inArray(pageloc, pageindex) >= 0) {
86 currentpage = pageloc;
87 }
88 }
89 log("Website", "You are currently on page: *" + currentpage + "*");
90 if(pageloc != "") {
91 if ($.inArray(pageloc, pageindex) >= 0) {
92 currentpage = pageloc;
93 loadpage($.inArray(pageloc, pageindex));
94 } else {
95 //Un-note next line to show 404 errors with wrong urls
96 //log("Client", "404 - The page '" + pageloc + "' does not exist. To ");
97 }
98 }
99 if(pageloc == "") {
100 log("Client", "What would you like to access?");
101 }
102 }
103 function getParam(name){
104 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
105 var regexS = "[\\?&]"+name+"=([^&#]*)";
106 var regex = new RegExp( regexS );
107 var results = regex.exec (window.location.href);
108 if (results == null) {
109 return "";
110 }
111 else {
112 return results[1];
113 }
114 }
115
116 function log(name, information) {
117 var d = new Date();
118 var hours = ((d.getHours() < 10) ? "0" : "") + d.getHours();
119 var minutes = ((d.getMinutes() < 10) ? "0" : "") + d.getMinutes();
120 var seconds = ((d.getSeconds() < 10) ? "0" : "") + d.getSeconds();
121 var colour = "whitet";
122 var textcolour = "";
123 var postcolour = "";
124
125 switch (name[0]) {
126 case "!":
127 postcolour = " important";
128 name = name.substr(1);
129 break;
130 }
131 switch (name) {
132 case "Website":
133 colour = "redt";
134 break;
135 case "Server":
136 colour = "bluet";
137 break;
138 case "Client":
139 colour = "bluet";
140 break;
141 case "User":
142 colour = "greent";
143 postcolour = " selft";
144 break;
145 }
146 if (information[0] == "A" && information[1] == "!") {
147 information = information.substr(2);
148 information = information.replace(/ /g, '\u00A0');
149 }
150 if (information[0] == "E" && information[1] == "!") {
151 information = information.substr(2);
152 postcolour = " important";
153 }
154
155 while (information.indexOf("](") >= 0) { //URL parser
156
157 var NAMEregExp = /\(([^)]+)\)/;
158 var uname = NAMEregExp.exec(information)[1];
159
160 var URLregExp = /\[([^)]+)\]/;
161 var url = URLregExp.exec(information)[1];
162 var newpage = false;
163 if (url[0] == "^") {
164 newpage = true;
165 url = url.substr(1);
166 }
167 var start = information.indexOf("[");
168 var end = information.indexOf(")");
169 if (newpage) {
170 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '" target="_blank">' + uname + '</a>');
171 } else {
172 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '">' + uname + '</a>');
173 }
174 //information = '<a href="' + url + '">' + uname + '</a>'; //working
175
176 }
177 var tobold = true;
178 var boldnumber = 0;
179 for (var i = 0; i < information.length; i++) {
180 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
181 boldnumber++;
182 }
183 }
184 while (information.indexOf("*") >= 0) { //Bold parser
185 var pos = information.indexOf("*");
186 information = information.replace("*", "");
187 if (tobold) {
188 information = information.splice(pos, 0, '<b>');
189 } else {
190 information = information.splice(pos, 0, '</b>');
191 }
192 tobold = !tobold;
193 if (tobold && boldnumber <= 1) {
194 break;
195 }
196 //information = '<a href="' + url + '">' + uname + '</a>'; //working
197 }
198 var tounderline = true;
199 var underlinenumber = 0;
200 for (var i = 0; i < information.length; i++) {
201 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
202 underlinenumber++;
203 }
204 }
205 while (information.indexOf("**") >= 0) { //Bold parser
206 var pos = information.indexOf("**");
207 information = information.replace("**", "");
208 if (tounderline) {
209 information = information.splice(pos, 0, '<u>');
210 } else {
211 information = information.splice(pos, 0, '</u>');
212 }
213 tounderline = !tounderline;
214 if (tounderline && underlinenumber <= 1) {
215 break;
216 }
217 //information = '<a href="' + url + '">' + uname + '</a>'; //working
218 } /**/
219 $(".stream").append('<div class="line">' +
220 '<p class="time">[' + hours + ":" + minutes + ":" + seconds + ']</p>' +
221 '<p class="name ' + colour + '">' + name + '</p>' +
222 '<p class="information' + postcolour + '">' + information + '</p>' +
223 '</div>');
224 $(document).scrollTop($(document).height() - $(window).height());
225 }
226 var timestring = "";
227 function time() {
228 var d = new Date();
229 var hours = d.getHours();
230 var minutes = d.getMinutes();
231 var seconds = d.getSeconds();
232 if (hours < 10) {
233 hours = "0" + hours;
234 }
235 if (minutes < 10) {
236 minutes = "0" + minutes;
237 }
238 if (seconds < 10) {
239 seconds = "0" + seconds;
240 }
241 var temptimestring = "[" + hours + ":" + minutes + ":" + seconds + "]";
242 if (temptimestring != timestring) {
243 timestring = temptimestring;
244 $(".editline .time").text(timestring);
245 }
246 }
247
248 var ctrldown = false;
249 $(".editline .edit").keydown(function(e) {
250 var text = $(".editline .edit").text();
251 console.log(e.which);
252 if (e.which == 13 && text !== "" && !ctrldown) {
253 var commands = text.split(' ');
254 var output = "";
255 if (commands[0] == "help") {
256 text = "/" + text;
257 }
258 $(".editline .edit").text("");
259 log("User", text);
260
261 previouscommands[currentcommand] = text;
262 currentcommand = previouscommands.length;
263 $(".editline .edit").keydown(35);
264 cmd(commands[0], text, commands);
265 /*Add mod commands*/
266 //modcmd(commands[0], text, commands);
267 /*Add mod commands*/
268
269 }
270 if (e.which == 38) { //up
271 if (currentcommand > 0) {
272 currentcommand--;
273 $(".editline .edit").text(previouscommands[currentcommand]);
274 }
275 }
276 if (e.which == 40) { //down
277
278 if (currentcommand < previouscommands.length) {
279 currentcommand++;
280 $(".editline .edit").text(previouscommands[currentcommand]);
281 }
282 }
283 });
284
285 function cmd(command, words, word) {
286 switch (word[0]) {
287 case "/help":
288 case "help":
289 for (var i = 0; i < commandlist.length; i++) {
290 output = commandlist[i][0] + " : " + commandlist[i][1];
291 //console.log(command[i][0]);
292 log("Client", output);
293 }
294 break;
295 case "/gl":
296 //window.location.href = "http://koya.io" + (currentpage == "landing" ? "" : "/" + currentpage);
297 window.history.pushState(currentpage, 'InpagePage', (currentpage == "landing" ? "/" : "/" + currentpage));
298 break;
299 case "/clear":
300 $(".stream").text("");
301 break;
302 case "/nav":
303 if ($.inArray(word[1], pageindex) >= 0) {
304 currentpage = word[1];
305 log("Website", "You are now in " + currentpage);
306 loadpage($.inArray(word[1], pageindex));
307 } else {
308 log("Client", "'" + word[1] + "' does not exist.");
309 }
310 break;
311 case "/list":
312 $.each(pageindex, function(id, content) {
313 log("Client", "> " + content);
314 });
315 break;
316 case "/login":
317 if (word.length >= 3) {
318 log("Client", "Attempting to login to " + word[1] + " with " + Array(word[2].length + 1).join("•"));
319 loginreturn = false;
320 //log("Client", "ER1");
321 setTimeout(loginemptyreturn, 20000);
322 } else {
323 log("Client", "Not enough arguments to log in, you need a USERNAME and a PASSWORD.");
324 }
325 break;
electrikjesus48c3b7e2017-04-28 21:45:48 -0400326 case "/brunch":
327 case "brunch":
electrikjesus17b70e42017-04-28 22:48:35 -0400328 if (word[1] == "bliss_kiwi") { window.open("https://downloads.blissroms.com/Bliss/Official/kiwi/");
329 }
330 else if(word[1] == "bliss_x86") { window.open("https://downloads.blissroms.com/Bliss/Official/x86/");
331 }
332 else if(word[1] == "bliss_axon7") { window.open("https://downloads.blissroms.com/Bliss/Official/axon7/");
333 }
334 else if(word[1] == "bliss_bacon") { window.open("https://downloads.blissroms.com/Bliss/Official/bacon/");
335 }
336 else if(word[1] == "bliss_bullhead") { window.open("https://downloads.blissroms.com/Bliss/Official/bullhead/");
337 }
338 else if(word[1] == "bliss_clark") { window.open("https://downloads.blissroms.com/Bliss/Official/clark/");
339 }
340 else if(word[1] == "bliss_hammerhead") { window.open("https://downloads.blissroms.com/Bliss/Official/hammerhead/");
341 }
342 else if(word[1] == "bliss_hydrogen") { window.open("https://downloads.blissroms.com/Bliss/Official/hydrogen/");
343 }
344 else if(word[1] == "bliss_kenzo") { window.open("https://downloads.blissroms.com/Bliss/Official/kenzo/");
345 }
346 else if(word[1] == "bliss_mako") { window.open("https://downloads.blissroms.com/Bliss/Official/mako/");
347 }
348 else if(word[1] == "bliss_oneplus2") { window.open("https://downloads.blissroms.com/Bliss/Official/oneplus2/");
349 }
350 else if(word[1] == "bliss_shamu") { window.open("https://downloads.blissroms.com/Bliss/Official/shamu/");
351 }
352 else if(word[1] == "bliss_victara") { window.open("https://downloads.blissroms.com/Bliss/Official/victara/");}
353 else if(word[1] == "bliss_warp4") { window.open("https://downloads.blissroms.com/Bliss/Official/warp4/");}
electrikjesus5f67e842017-04-28 22:55:55 -0400354 else {
355 output = "Unrecognized device";
356 log("Client", output);
357 }
electrikjesus48c3b7e2017-04-28 21:45:48 -0400358 break;
electrikjesusb84b56e2017-04-28 13:31:09 -0400359 default:
360 output = "Unrecognised command '" + word[0] + "'.";
361 log("Client", output);
362 }
363 }
364
365 function loadpage(i) {
366 $.each(pages[i], function(id, content) {
367 if (content != pageindex[i]) {
368 log("Website", content);
369 }
370 });
371 }
372 var loginreturn = false;
373
374 function loginemptyreturn() {
375 //log("Client", "ER2");
376 if (!loginreturn) {
377 log("Client", "E![LOGIN] No Return Recieved");
378 }
379 }
380 String.prototype.splice = function(idx, rem, str) {
381 return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
382 };
383 init();
384});