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