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