diff src/site.js @ 4:8896ffd7b152

start login
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 22 Oct 2023 23:53:59 -0600
parents
children 88f425d261b3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/site.js	Sun Oct 22 23:53:59 2023 -0600
@@ -0,0 +1,49 @@
+'use strict';
+
+function ajax(url,postData,context) {
+	let request = new XMLHttpRequest();
+	let method = postData ? 'POST' : 'GET';
+	request.open( method, url );
+	if( postData )
+		request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
+	request.onload = function() {
+		if( request.status !== 200 ) {
+			console.log( 'ajax failed: ' + request.status );
+			if( request.responseText )
+				document.write('<pre>'+request.responseText+'</pre>');
+			return;
+		}
+		try {
+			eval( request.responseText );
+		} catch(e) {
+			console.log( request.responseText );
+			window.err = '\najax-url = ' + url;
+			throw e;
+		}
+	};
+	request.send(postData);
+}
+
+window.onerror = function(msg, url, line, col, error) {
+	if (!url)
+		return;
+	let err = msg;
+	err += '\nurl = ' + url;
+	if (url != window.location)
+		err += '\npage = ' + window.location;
+	err += '\nline = '+line;
+	if (col)
+		err += '\ncolumn = ' + col;
+	if (error && error.stack)
+		err += '\nstack = ' + error.stack;
+	if( window.err ) {
+		err += window.err;
+		window.err = null;
+	}
+	ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
+};
+
+function logout() {
+	document.cookie = 'user=; Max-Age=0; path=/;';
+	location = '/';
+}