blob: 3118c861aab7a9855be28ec09a54ca195900b9e9 [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"],
18 ["/gl", "Generate a url for the current page - [^http://koya.io/](This doesn't work in an iframe, try it at *Koya.io*) outputs something like [^http://koya.io/connect](*koya.io/connect*)"],
19 ["/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*/
26 ["index", "Welcome to Koya.io", "Simply, this is just a sandbox in which to add to; no real point - a couple of features that I plan to add though:", "URL shortner and open tracker, just enter a URL into the command line and press enter and you will get 2 links - 1 which looks like [http://koya.io/XXXXXX](http://koya.io/XXXXXX) and another [http://koya.io/u/XXXXXX](http://koya.io/u/XXXXXX) : they will both forward but the second will show a preview of the full url so they know where you are going.", "You can also save small messages with `/msg <string <160 chars>` and you will get a url like [http://koya.io/XXXXXX](http://koya.io/XXXXXX)","Pressing Ctrl+v will paste the short text or image and you will get a link.", "There will be accounts but likely given out rather than being able to register them whenever, this is a personal site so idk."],
27 ["about", "About Koya.io", "Personal power website for Finn 'Koya' Shackleton.", "Will include some features which too are mainly for personal use: Link shortner, image host, pastebin and any sandbox testing", "The colours have been taken from [https://github.com/Poorchop/darktooth-theme-ports/tree/8c852e8edde8df57d831dc8631493b0565fadbbc/hexchat-darktooth](Poorchop's Darktooth HexChat theme)", "In the process of turning the website into a server sided thing, currently what you can read is in the [http://koya.io/scripts.js](JavaScript file)!"],
28 ["connect", "Connect with Koya",
29 "[mailto:_@koya.io](Email _@koya.io)",
30 "[skype:finn.shackleton](Skype)",
31 "[^http://steamcommunity.com/id/bananabutterscotchmaplepancakes](Steam) < Always available",
32 "[^http://codepen.io/OfficialAntarctica](Codepen)",
33 "[^http://everybodyedits.com/profiles/bbmp](Everybody Edits)"]
34 ];
35 var pageindex = ["index", "about", "connect"];
36 var currentpage = "landing";
37 var url = "http://koya.io/"
38 /*
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());
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!********************************");
62 log("Website", "A!Have A Truly Blissful Experience");
63 log("Website", "A!********************************");
64 log("Website", "");
65 log("Website", "E!Bliss ROMs temporary site [^http://blissroms.io/](*blissroms.io*)");
66 log("Website", "");
67 log("Website", "A!********************************");
68 log("Website", "");
69 log("Website", "E![^http://downloads.blissroms.com/](*Bliss Downloads*) , [^http://paypal.me/TeamBliss](*Donate to Team Bliss*)");
70 urlvars();
71 log("Client", "For help say '/help'");
72 setInterval(favicon,500);
73 }
74
75 function urlvars() {
76 var pagelocs = window.location.pathname.replace("/","").split("/");
77 var pageloc = pagelocs[0];
78 console.log(pageloc);
79 //alert();
80 if(pageloc != "") {
81 if ($.inArray(pageloc, pageindex) >= 0) {
82 currentpage = pageloc;
83 }
84 }
85 log("Website", "You are currently on page: *" + currentpage + "*");
86 if(pageloc != "") {
87 if ($.inArray(pageloc, pageindex) >= 0) {
88 currentpage = pageloc;
89 loadpage($.inArray(pageloc, pageindex));
90 } else {
91 //Un-note next line to show 404 errors with wrong urls
92 //log("Client", "404 - The page '" + pageloc + "' does not exist. To ");
93 }
94 }
95 if(pageloc == "") {
96 log("Client", "What would you like to access?");
97 }
98 }
99 function getParam(name){
100 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
101 var regexS = "[\\?&]"+name+"=([^&#]*)";
102 var regex = new RegExp( regexS );
103 var results = regex.exec (window.location.href);
104 if (results == null) {
105 return "";
106 }
107 else {
108 return results[1];
109 }
110 }
111
112 function log(name, information) {
113 var d = new Date();
114 var hours = ((d.getHours() < 10) ? "0" : "") + d.getHours();
115 var minutes = ((d.getMinutes() < 10) ? "0" : "") + d.getMinutes();
116 var seconds = ((d.getSeconds() < 10) ? "0" : "") + d.getSeconds();
117 var colour = "whitet";
118 var textcolour = "";
119 var postcolour = "";
120
121 switch (name[0]) {
122 case "!":
123 postcolour = " important";
124 name = name.substr(1);
125 break;
126 }
127 switch (name) {
128 case "Website":
129 colour = "redt";
130 break;
131 case "Server":
132 colour = "bluet";
133 break;
134 case "Client":
135 colour = "bluet";
136 break;
137 case "User":
138 colour = "greent";
139 postcolour = " selft";
140 break;
141 }
142 if (information[0] == "A" && information[1] == "!") {
143 information = information.substr(2);
144 information = information.replace(/ /g, '\u00A0');
145 }
146 if (information[0] == "E" && information[1] == "!") {
147 information = information.substr(2);
148 postcolour = " important";
149 }
150
151 while (information.indexOf("](") >= 0) { //URL parser
152
153 var NAMEregExp = /\(([^)]+)\)/;
154 var uname = NAMEregExp.exec(information)[1];
155
156 var URLregExp = /\[([^)]+)\]/;
157 var url = URLregExp.exec(information)[1];
158 var newpage = false;
159 if (url[0] == "^") {
160 newpage = true;
161 url = url.substr(1);
162 }
163 var start = information.indexOf("[");
164 var end = information.indexOf(")");
165 if (newpage) {
166 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '" target="_blank">' + uname + '</a>');
167 } else {
168 information = information.replace(information.substring(start, end + 1), "").splice(start, 0, '<a href="' + url + '">' + uname + '</a>');
169 }
170 //information = '<a href="' + url + '">' + uname + '</a>'; //working
171
172 }
173 var tobold = true;
174 var boldnumber = 0;
175 for (var i = 0; i < information.length; i++) {
176 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
177 boldnumber++;
178 }
179 }
180 while (information.indexOf("*") >= 0) { //Bold parser
181 var pos = information.indexOf("*");
182 information = information.replace("*", "");
183 if (tobold) {
184 information = information.splice(pos, 0, '<b>');
185 } else {
186 information = information.splice(pos, 0, '</b>');
187 }
188 tobold = !tobold;
189 if (tobold && boldnumber <= 1) {
190 break;
191 }
192 //information = '<a href="' + url + '">' + uname + '</a>'; //working
193 }
194 var tounderline = true;
195 var underlinenumber = 0;
196 for (var i = 0; i < information.length; i++) {
197 if (information[i] == "*" && information[i - 1] != "*" && information[i + 1] != "*") {
198 underlinenumber++;
199 }
200 }
201 while (information.indexOf("**") >= 0) { //Bold parser
202 var pos = information.indexOf("**");
203 information = information.replace("**", "");
204 if (tounderline) {
205 information = information.splice(pos, 0, '<u>');
206 } else {
207 information = information.splice(pos, 0, '</u>');
208 }
209 tounderline = !tounderline;
210 if (tounderline && underlinenumber <= 1) {
211 break;
212 }
213 //information = '<a href="' + url + '">' + uname + '</a>'; //working
214 } /**/
215 $(".stream").append('<div class="line">' +
216 '<p class="time">[' + hours + ":" + minutes + ":" + seconds + ']</p>' +
217 '<p class="name ' + colour + '">' + name + '</p>' +
218 '<p class="information' + postcolour + '">' + information + '</p>' +
219 '</div>');
220 $(document).scrollTop($(document).height() - $(window).height());
221 }
222 var timestring = "";
223 function time() {
224 var d = new Date();
225 var hours = d.getHours();
226 var minutes = d.getMinutes();
227 var seconds = d.getSeconds();
228 if (hours < 10) {
229 hours = "0" + hours;
230 }
231 if (minutes < 10) {
232 minutes = "0" + minutes;
233 }
234 if (seconds < 10) {
235 seconds = "0" + seconds;
236 }
237 var temptimestring = "[" + hours + ":" + minutes + ":" + seconds + "]";
238 if (temptimestring != timestring) {
239 timestring = temptimestring;
240 $(".editline .time").text(timestring);
241 }
242 }
243
244 var ctrldown = false;
245 $(".editline .edit").keydown(function(e) {
246 var text = $(".editline .edit").text();
247 console.log(e.which);
248 if (e.which == 13 && text !== "" && !ctrldown) {
249 var commands = text.split(' ');
250 var output = "";
251 if (commands[0] == "help") {
252 text = "/" + text;
253 }
254 $(".editline .edit").text("");
255 log("User", text);
256
257 previouscommands[currentcommand] = text;
258 currentcommand = previouscommands.length;
259 $(".editline .edit").keydown(35);
260 cmd(commands[0], text, commands);
261 /*Add mod commands*/
262 //modcmd(commands[0], text, commands);
263 /*Add mod commands*/
264
265 }
266 if (e.which == 38) { //up
267 if (currentcommand > 0) {
268 currentcommand--;
269 $(".editline .edit").text(previouscommands[currentcommand]);
270 }
271 }
272 if (e.which == 40) { //down
273
274 if (currentcommand < previouscommands.length) {
275 currentcommand++;
276 $(".editline .edit").text(previouscommands[currentcommand]);
277 }
278 }
279 });
280
281 function cmd(command, words, word) {
282 switch (word[0]) {
283 case "/help":
284 case "help":
285 for (var i = 0; i < commandlist.length; i++) {
286 output = commandlist[i][0] + " : " + commandlist[i][1];
287 //console.log(command[i][0]);
288 log("Client", output);
289 }
290 break;
291 case "/gl":
292 //window.location.href = "http://koya.io" + (currentpage == "landing" ? "" : "/" + currentpage);
293 window.history.pushState(currentpage, 'InpagePage', (currentpage == "landing" ? "/" : "/" + currentpage));
294 break;
295 case "/clear":
296 $(".stream").text("");
297 break;
298 case "/nav":
299 if ($.inArray(word[1], pageindex) >= 0) {
300 currentpage = word[1];
301 log("Website", "You are now in " + currentpage);
302 loadpage($.inArray(word[1], pageindex));
303 } else {
304 log("Client", "'" + word[1] + "' does not exist.");
305 }
306 break;
307 case "/list":
308 $.each(pageindex, function(id, content) {
309 log("Client", "> " + content);
310 });
311 break;
312 case "/login":
313 if (word.length >= 3) {
314 log("Client", "Attempting to login to " + word[1] + " with " + Array(word[2].length + 1).join("•"));
315 loginreturn = false;
316 //log("Client", "ER1");
317 setTimeout(loginemptyreturn, 20000);
318 } else {
319 log("Client", "Not enough arguments to log in, you need a USERNAME and a PASSWORD.");
320 }
321 break;
322 default:
323 output = "Unrecognised command '" + word[0] + "'.";
324 log("Client", output);
325 }
326 }
327
328 function loadpage(i) {
329 $.each(pages[i], function(id, content) {
330 if (content != pageindex[i]) {
331 log("Website", content);
332 }
333 });
334 }
335 var loginreturn = false;
336
337 function loginemptyreturn() {
338 //log("Client", "ER2");
339 if (!loginreturn) {
340 log("Client", "E![LOGIN] No Return Recieved");
341 }
342 }
343 String.prototype.splice = function(idx, rem, str) {
344 return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
345 };
346 init();
347});