Farow / openuserjs.org Autologin

// ==UserScript==
// @name        openuserjs.org Autologin
// @namespace   openuserjs.org
// @oujs:author cuzi
// @version     1.0.3
// @include     https://openuserjs.org/*
// @grant       @none
// @license MIT
// ==/UserScript==

'use strict';

/*
	Changelog

		2018-01-20 - 1.0.3
			- no need to redirect anymore, oujs does so automatically now, removed GM_* dependencies
			- @include is no longer a regexp
			- while logging in the cursor is changed to 'wait'
		2014-09-17 - 1.0.2
			- now works in a similar way the default log in process,
			  redirecting you to the other services if you're logged out of them
		2014-09-15 - 1.0.1 - fixed custom username not working
		2014-09-13 - 1.0.0 - initial release
*/

let username = 'Farow'; /* your username */

if (document.getElementsByClassName('fa-sign-in').length) {
	let style = document.createElement('style');

	style.type = 'text/css';
	style.appendChild(document.createTextNode('* { cursor: wait; }'));

	document.head.appendChild(style);
	post('/auth/', { 'username': encodeURIComponent(username) });
}

/* from http://stackoverflow.com/a/133997 */
function post(path, params, method) {
	method = method || 'post'; // Set method to post by default if not specified.

	// The rest of this code assumes you are not using a library.
	// It can be made less wordy if you use one.
	var form = document.createElement('form');
	form.setAttribute('method', method);
	form.setAttribute('action', path);

	for(var key in params) {
		if(params.hasOwnProperty(key)) {
			var hiddenField = document.createElement('input');
			hiddenField.setAttribute('type', 'hidden');
			hiddenField.setAttribute('name', key);
			hiddenField.setAttribute('value', params[key]);

			form.appendChild(hiddenField);
		}
	}

	document.body.appendChild(form);
	form.submit();
}