blob: 77b1ea041a25d99fbe3212afc6534b47d0ff4d5b [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)",
electrikjesus8c0536e2017-05-11 09:30:51 -040033 "[^https://review.blissroms.com](Gerrit Code Review for Blissroms)",
electrikjesus48301812017-05-07 14:11:12 -040034 "[^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", "");
electrikjesus1c821f62017-05-11 09:47:07 -040073 log("Website", "E![^https://goo.gl/kAb7ti](*Join Bliss Family of ROMs*)");
74 log("Website", "");
electrikjesus2c4c1192017-04-28 18:08:46 -040075 log("Website", "A!********************************");
electrikjesus430554b2017-04-28 16:21:07 -040076 urlvars();
electrikjesusb84b56e2017-04-28 13:31:09 -040077 log("Client", "For help say '/help'");
78 setInterval(favicon,500);
79 }
80
81 function urlvars() {
82 var pagelocs = window.location.pathname.replace("/","").split("/");
83 var pageloc = pagelocs[0];
84 console.log(pageloc);
85 //alert();
86 if(pageloc != "") {
87 if ($.inArray(pageloc, pageindex) >= 0) {
88 currentpage = pageloc;
89 }
90 }
91 log("Website", "You are currently on page: *" + currentpage + "*");
92 if(pageloc != "") {
93 if ($.inArray(pageloc, pageindex) >= 0) {
94 currentpage = pageloc;
95 loadpage($.inArray(pageloc, pageindex));
96 } else {
97 //Un-note next line to show 404 errors with wrong urls
98 //log("Client", "404 - The page '" + pageloc + "' does not exist. To ");
99 }
100 }
101 if(pageloc == "") {
102 log("Client", "What would you like to access?");
103 }
104 }
105 function getParam(name){
106 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
107 var regexS = "[\\?&]"+name+"=([^&#]*)";
108 var regex = new RegExp( regexS );
109 var results = regex.exec (window.location.href);
110 if (results == null) {
111 return "";
112 }
113 else {
114 return results[1];
115 }
116 }
117
118 function log(name, information) {
119 var d = new Date();
120 var hours = ((d.getHours() < 10) ? "0" : "") + d.getHours();
121 var minutes = ((d.getMinutes() < 10) ? "0" : "") + d.getMinutes();
122 var seconds = ((d.getSeconds() < 10) ? "0" : "") + d.getSeconds();
123 var colour = "whitet";
124 var textcolour = "";
125 var postcolour = "";
126
127 switch (name[0]) {
128 case "!":
129 postcolour = " important";
130 name = name.substr(1);
131 break;
132 }
133 switch (name) {
134 case "Website":
135 colour = "redt";
136 break;
137 case "Server":
138 colour = "bluet";
139 break;
140 case "Client":
141 colour = "bluet";
142 break;
143 case "User":
144 colour = "greent";
145 postcolour = " selft";
146 break;
147 }
148 if (information[0] == "A" && information[1] == "!") {
149 information = information.substr(2);
150 information = information.replace(/ /g, '\u00A0');
151 }
152 if (information[0] == "E" && information[1] == "!") {
153 information = information.substr(2);
154 postcolour = " important";
155 }
156
157 while (information.indexOf("](") >= 0) { //URL parser
158
159 var NAMEregExp = /\(([^)]+)\)/;
160 var uname = NAMEregExp.exec(information)[1];
161
162 var URLregExp = /\[([^)]+)\]/;
163 var url = URLregExp.exec(information)[1];
164 var newpage = false;
165 if (url[0] == "^") {
166 newpage = true;
167 url = url.substr(1);
168 }
169 var start = information.indexOf("[");
170 var end = information.indexOf(")");
171 if (newpage) {
172 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '" target="_blank">' + uname + '</a>');
173 } else {
174 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '">' + uname + '</a>');
175 }
176 //information = '<a href="' + url + '">' + uname + '</a>'; //working
177
178 }
179 var tobold = true;
180 var boldnumber = 0;
181 for (var i = 0; i < information.length; i++) {
182 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
183 boldnumber++;
184 }
185 }
186 while (information.indexOf("*") >= 0) { //Bold parser
187 var pos = information.indexOf("*");
188 information = information.replace("*", "");
189 if (tobold) {
190 information = information.splice(pos, 0, '<b>');
191 } else {
192 information = information.splice(pos, 0, '</b>');
193 }
194 tobold = !tobold;
195 if (tobold && boldnumber <= 1) {
196 break;
197 }
198 //information = '<a href="' + url + '">' + uname + '</a>'; //working
199 }
200 var tounderline = true;
201 var underlinenumber = 0;
202 for (var i = 0; i < information.length; i++) {
203 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
204 underlinenumber++;
205 }
206 }
207 while (information.indexOf("**") >= 0) { //Bold parser
208 var pos = information.indexOf("**");
209 information = information.replace("**", "");
210 if (tounderline) {
211 information = information.splice(pos, 0, '<u>');
212 } else {
213 information = information.splice(pos, 0, '</u>');
214 }
215 tounderline = !tounderline;
216 if (tounderline && underlinenumber <= 1) {
217 break;
218 }
219 //information = '<a href="' + url + '">' + uname + '</a>'; //working
220 } /**/
221 $(".stream").append('<div class="line">' +
222 '<p class="time">[' + hours + ":" + minutes + ":" + seconds + ']</p>' +
223 '<p class="name ' + colour + '">' + name + '</p>' +
224 '<p class="information' + postcolour + '">' + information + '</p>' +
225 '</div>');
226 $(document).scrollTop($(document).height() - $(window).height());
227 }
228 var timestring = "";
229 function time() {
230 var d = new Date();
231 var hours = d.getHours();
232 var minutes = d.getMinutes();
233 var seconds = d.getSeconds();
234 if (hours < 10) {
235 hours = "0" + hours;
236 }
237 if (minutes < 10) {
238 minutes = "0" + minutes;
239 }
240 if (seconds < 10) {
241 seconds = "0" + seconds;
242 }
243 var temptimestring = "[" + hours + ":" + minutes + ":" + seconds + "]";
244 if (temptimestring != timestring) {
245 timestring = temptimestring;
246 $(".editline .time").text(timestring);
247 }
248 }
249
250 var ctrldown = false;
251 $(".editline .edit").keydown(function(e) {
252 var text = $(".editline .edit").text();
253 console.log(e.which);
254 if (e.which == 13 && text !== "" && !ctrldown) {
255 var commands = text.split(' ');
256 var output = "";
257 if (commands[0] == "help") {
258 text = "/" + text;
259 }
260 $(".editline .edit").text("");
261 log("User", text);
262
263 previouscommands[currentcommand] = text;
264 currentcommand = previouscommands.length;
265 $(".editline .edit").keydown(35);
266 cmd(commands[0], text, commands);
267 /*Add mod commands*/
268 //modcmd(commands[0], text, commands);
269 /*Add mod commands*/
270
271 }
272 if (e.which == 38) { //up
273 if (currentcommand > 0) {
274 currentcommand--;
275 $(".editline .edit").text(previouscommands[currentcommand]);
276 }
277 }
278 if (e.which == 40) { //down
279
280 if (currentcommand < previouscommands.length) {
281 currentcommand++;
282 $(".editline .edit").text(previouscommands[currentcommand]);
283 }
284 }
285 });
286
287 function cmd(command, words, word) {
288 switch (word[0]) {
289 case "/help":
290 case "help":
291 for (var i = 0; i < commandlist.length; i++) {
292 output = commandlist[i][0] + " : " + commandlist[i][1];
293 //console.log(command[i][0]);
294 log("Client", output);
295 }
296 break;
297 case "/gl":
298 //window.location.href = "http://koya.io" + (currentpage == "landing" ? "" : "/" + currentpage);
299 window.history.pushState(currentpage, 'InpagePage', (currentpage == "landing" ? "/" : "/" + currentpage));
300 break;
301 case "/clear":
302 $(".stream").text("");
303 break;
304 case "/nav":
305 if ($.inArray(word[1], pageindex) >= 0) {
306 currentpage = word[1];
307 log("Website", "You are now in " + currentpage);
308 loadpage($.inArray(word[1], pageindex));
309 } else {
310 log("Client", "'" + word[1] + "' does not exist.");
311 }
312 break;
313 case "/list":
314 $.each(pageindex, function(id, content) {
315 log("Client", "> " + content);
316 });
317 break;
318 case "/login":
319 if (word.length >= 3) {
320 log("Client", "Attempting to login to " + word[1] + " with " + Array(word[2].length + 1).join("•"));
321 loginreturn = false;
322 //log("Client", "ER1");
323 setTimeout(loginemptyreturn, 20000);
324 } else {
325 log("Client", "Not enough arguments to log in, you need a USERNAME and a PASSWORD.");
326 }
327 break;
electrikjesus48c3b7e2017-04-28 21:45:48 -0400328 case "/brunch":
329 case "brunch":
electrikjesus17b70e42017-04-28 22:48:35 -0400330 if (word[1] == "bliss_kiwi") { window.open("https://downloads.blissroms.com/Bliss/Official/kiwi/");
331 }
332 else if(word[1] == "bliss_x86") { window.open("https://downloads.blissroms.com/Bliss/Official/x86/");
333 }
334 else if(word[1] == "bliss_axon7") { window.open("https://downloads.blissroms.com/Bliss/Official/axon7/");
335 }
336 else if(word[1] == "bliss_bacon") { window.open("https://downloads.blissroms.com/Bliss/Official/bacon/");
337 }
338 else if(word[1] == "bliss_bullhead") { window.open("https://downloads.blissroms.com/Bliss/Official/bullhead/");
339 }
340 else if(word[1] == "bliss_clark") { window.open("https://downloads.blissroms.com/Bliss/Official/clark/");
341 }
342 else if(word[1] == "bliss_hammerhead") { window.open("https://downloads.blissroms.com/Bliss/Official/hammerhead/");
343 }
344 else if(word[1] == "bliss_hydrogen") { window.open("https://downloads.blissroms.com/Bliss/Official/hydrogen/");
345 }
346 else if(word[1] == "bliss_kenzo") { window.open("https://downloads.blissroms.com/Bliss/Official/kenzo/");
347 }
348 else if(word[1] == "bliss_mako") { window.open("https://downloads.blissroms.com/Bliss/Official/mako/");
349 }
350 else if(word[1] == "bliss_oneplus2") { window.open("https://downloads.blissroms.com/Bliss/Official/oneplus2/");
351 }
352 else if(word[1] == "bliss_shamu") { window.open("https://downloads.blissroms.com/Bliss/Official/shamu/");
353 }
354 else if(word[1] == "bliss_victara") { window.open("https://downloads.blissroms.com/Bliss/Official/victara/");}
355 else if(word[1] == "bliss_warp4") { window.open("https://downloads.blissroms.com/Bliss/Official/warp4/");}
electrikjesus5f67e842017-04-28 22:55:55 -0400356 else {
357 output = "Unrecognized device";
358 log("Client", output);
359 }
electrikjesus48c3b7e2017-04-28 21:45:48 -0400360 break;
electrikjesusb84b56e2017-04-28 13:31:09 -0400361 default:
362 output = "Unrecognised command '" + word[0] + "'.";
363 log("Client", output);
364 }
365 }
366
367 function loadpage(i) {
368 $.each(pages[i], function(id, content) {
369 if (content != pageindex[i]) {
370 log("Website", content);
371 }
372 });
373 }
374 var loginreturn = false;
375
376 function loginemptyreturn() {
377 //log("Client", "ER2");
378 if (!loginreturn) {
379 log("Client", "E![LOGIN] No Return Recieved");
380 }
381 }
382 String.prototype.splice = function(idx, rem, str) {
383 return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
384 };
385 init();
386});