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