Raw Source
jerone / Multiple Windows Live IDs

// ==UserScript==
// @name             Multiple Windows Live IDs
// @id               Multiple_Windows_Live_IDs@https://github.com/jerone/UserScripts
// @namespace        https://github.com/jerone/UserScripts
// @description      Easy login with multiple Microsoft accounts.
// @author           jerone
// @copyright        2014+, jerone (https://github.com/jerone)
// @license          CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @license          GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @homepage         https://github.com/jerone/UserScripts/tree/master/Multiple_Windows_Live_IDs
// @homepageURL      https://github.com/jerone/UserScripts/tree/master/Multiple_Windows_Live_IDs
// @downloadURL      https://github.com/jerone/UserScripts/raw/master/Multiple_Windows_Live_IDs/Multiple_Windows_Live_IDs.user.js
// @updateURL        https://github.com/jerone/UserScripts/raw/master/Multiple_Windows_Live_IDs/Multiple_Windows_Live_IDs.user.js
// @supportURL       https://github.com/jerone/UserScripts/issues
// @contributionURL  https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
// @version          0.2.0
// @grant            GM_getValue
// @grant            GM_setValue
// @run-at           document-end
// @include          http*://login.live.com*
// ==/UserScript==

// cSpell:ignore MWLID, maincontent, phholder, transform
/* eslint security/detect-object-injection: "off" */

(function () {
	var autoLogin = true;
	var addPassMask = true;

	window.setTimeout(function () {
		var profileString = GM_getValue("MWLID.profiles"),
			profiles = [
				{ name: "Account 1", mail: "test1@live.com", pass: "P@ssw0rd" },
				{
					name: "Account 2",
					mail: "test2@live.com",
					pass: "P@ssw0rd",
					photo: "data:image/gif;base64,abcd",
				},
				{
					name: "Account 3",
					mail: "test3@live.com",
					pass: "P@ssw0rd",
					photo: "http://my.pictu.re/img.png",
				},
				{
					name: "Account 4",
					mail: "test4@live.com",
					pass: "P@ssw0rd",
					color: "#EB008B",
				},
			];
		if (profileString == null) {
			GM_setValue("MWLID.profiles", JSON.stringify(profiles));
		} else {
			profiles = JSON.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9JTrofYZIq17FhhFol5zgOyQZO1iyfbdixPK8wiiYNM4yymQkxm4Avb9nPQ8rQ4LJI4uORk736KuujiT8vTRSwSB8Z/3tlju7OTx1H/i4NkeVphvrh5NlXu6Dt4Z4/dU+5xctSEJe6VOqjrvl/V+AN53EekRyYdxwAAAABJRU5ErkJggg==",
			rightDark:
				"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFFSURBVDhPjZI7L0RRFEYvkWg8Eo9aRbQalZJEIjIq0fgDmvEDFEo/QkckKrVQUXslyikUIhKdhFCx1j4zXHfO3FjJSu45uee191dkWMJDfMAPfMEL3MYh7MkknuIr7uEizuI8buEVPuMyduHiFp7jlBMZBnAH33HdiTKe7OK+GNWziW4yEyPwzV67erKb7eIBjjlR4gSP02cqmG/OMY43eN3+7jCNnzjiwGpbMPGnhYoNfMRbLG/iOm8frbLasoZfNZ5hP8olWo/os62SOdzP+IReeRU73KG3i5DY515YSG+5EqPEMDoXnTBhhsQ+V8ktlibep88UTxNmSMrYxgkcjdEvduANN2LUxngajihKDS727UfYFTrj6SaGxB/L+Gav7ckuHsQsFsWEWXH7bKs80Tr4Zq/9n7hHwgyJT7JVP7n/S1F8A7gwSnemTnsFAAAAAElFTkSuQmCC",

			editLight:
				"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAKxJREFUOE+tjbENQjEMBSPRgIRAomQFWIIp6FiJigUYgI6eipIZWIEJwjm2QYp+fizESdc4772kCDnnGd7wgWs7x6AwxQXeUYiPEJyj/HzGFcZHCHjZiY/wUJedeuRqlS8cW2XHRy64tZrCoVd2jjixmsIhWn7izz//uSxw3JXncYbLAg8b3EuqQbssaCYfcGhkvCxorlCP9MuCZj/4SKwsEHyhc7Lbsjx2SekNzHko02Qtti8AAAAASUVORK5CYII=",
			editDark:
				"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAKtJREFUOE+lzU0OwWAUheEmJiRCYmgLugmrMLMlIxuwADNzI0NrsAUr+LxHeqS9/eiPmzyS0vcoUkqduBmuuGPd+K3+kMNNscAN+qIx0grquDn0zyes0BrJhsI51oNkR/rGFkcuQ2LzyBnl0NgOmLybEfED5af7J67a8bEHtogvR9nYAxvsECP7GotOn3vkRn7GovPLcaQzFp0D8UivWHRPeOBYfbmML+al4gWQp6tCc9RDvgAAAABJRU5ErkJggg==",

			deleteLight:
				"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAJdJREFUOE+lk9sRwyAMBOkvqScFpAc3kB5cSQoia+vO2A4fPHZGo5NAMiNDyjmnKe4NiJ+Sf7D2kCycG6Df2Mai1AG5Vyzlj1IBCXsXm6MJ2sWmNCGoFZsFuxebaIKofaGFOCHCvqdJmRGBVHOT64BJSAXE676tzlfbCiSlJk+AH58BNvcXsLl7ID9+Ew16/C0Y4o7XmNIPDBJZ6y59BrgAAAAASUVORK5CYII=",
			deleteDark:
				"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAJBJREFUOE+lk4ERgCAIRd2v5mmAdnCBdmiSBrIvgRKlV/ju/l0g/EPTkEkpufUwALOOtcD0kqsGYM0hFHURry28tpn8ZQCkWVRMgDSLiolgm0URss0iMhFaRT3RhERjzJ709pCpwReT2wETJrHnVEOHruV6rNTAPwHwnwEY+wtg7B7wh/8mqsD/FlTix2tM4QQu9ZqctQdDpAAAAABJRU5ErkJggg==",

			addLight:
				"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAnklEQVRYR+3WQQqFMBRD0e5/bW7HcTWkZCRK+lBUcuAN+29m3zaj977s51rG8/shxqYlAwUxNi0ZKIixaclAQYxNSwYKYmxaMlAQY9Py04F4OHHrfi68Ofqt08PAV8vAqgysysCqDKzKwKpPDDz8k7645z4WZozHrnywCmJsWjJQEGPTkoGCGJuWDBTE2LRkoCDGpiUDBTE2LRMDW9sAWMFNgzVOe18AAAAASUVORK5CYII=",

			header: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQQAAAAyCAYAAAC6XKUOAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAmxSURBVHhe7ZxtiFVFGMcvBIEgSEEQCEERCEEQBH0SAulD4KcgCYIgCARFdO9SWBmFFGmFIUhBL1BEUlwjECLLrTTu7lq5ZppltmksmtZqtmVpmXWa/5wz987Mec6cOeeelz3b84MH1zvzPHPn7jz/eTmzt8UwDFMP7feubA2NLWmtGR1utUdfa63cNT8q8aNuf4ZhcrLq42tb7e4dIgHXt9pj24VNtYbHA8OWjyyIasep259hmJysGb1J2L1i1t0sEnC3SL6ZWP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QEEQXRYLFQNAcggsguQJBYJHFARfAEByn4BAcgBNg0QhIMGVes0t+C01qMEzykv2zM23za/+prliIozg7zHjsatUShG4ir4EdGbIlYRxEBK9iJ+YOM17syZYekolYEu6IqvDYRY5OoYG4C8wthgt/5jCHyJClU/hrNy6ijSFNxUPE25jxEBmy+HTt5IcNB2koniLKAR47RBaP7vtyJhykpUiLKewQWc50rSf6Ij5/JarFgB0iS4fuh0biWxnYNVLcdEr6hxppLPYO8y9k9gJmuVYpcnk0owAAAABJRU5ErkJggg==",
		};

		function proxy(fn) {
			return function () {
				var that = this;
				return function (e) {
					var args = that.slice(0); // clone;
					args.unshift(e); // prepend event;
					fn.apply(this, args);
				};
			}.call([].slice.call(arguments, 1));
		}

		function fireEvent(elm, eventName) {
			var event = document.createEvent("HTMLEvents");
			event.initEvent(eventName, true, true);
			elm.dispatchEvent(event);
		}

		function addEventListeners(elm, eventNames, fn) {
			Array.forEach(eventNames, function (event) {
				elm.addEventListener(event, fn);
			});
		}

		function getContrastYIQ(hexcolor) {
			hexcolor = hexcolor.replace("#", "");
			var r = parseInt(hexcolor.substr(0, 2), 16),
				g = parseInt(hexcolor.substr(2, 2), 16),
				b = parseInt(hexcolor.substr(4, 2), 16),
				yiq = (r * 299 + g * 587 + b * 114) / 1000;
			return yiq >= 200;
		}

		var metroColors = [
				"#00AEDB",
				"#00B159",
				"#F37735",
				"#7C4199",
				"#FFC425",
				"#EC098C",
				"#D11141",
				"#000000",
			],
			metroColorsIndex = -1;

		var css =
			// layout;
			"#maincontent, #accountTD { display: inline-block; }" +
			// accounts;
			"#accountTD { font-size: 12px; width: 500px; min-height: 400px; margin: 5px; }" +
			"#accountTD .profile { text-transform: uppercase; color: #FFFFFF; cursor: pointer; float: left; height: 150px; position: relative; margin: 5px; padding: 5px; text-align: center; width: 150px; }" +
			"#accountTD .profile:hover{ opacity: 0.85; }" +
			"#accountTD .profile.dark { color: #000000; }" +
			"#accountTD .profile > img { max-height: 100px; max-width: 100px; vertical-align: middle; }" +
			"#accountTD .profile > span { bottom: 0; left: 0; margin: 5px; overflow: hidden; position: absolute; text-overflow: ellipsis; white-space: nowrap; width: 140px; }" +
			"#accountTD .profile > div { display: none; position: absolute; right: 0; top: 0; }" +
			"#accountTD .profile > div img { opacity: 0.3; margin: 4px 4px 0 0; }" +
			"#accountTD .profile:hover > div { display: block; }" +
			"#accountTD .profile:hover > div img:hover { opacity: 1; }" +
			// add account button;
			"#accountTD .addAccountBtn { opacity: 0.6; width: 100px; height: 100px; }" +
			"#accountTD .addAccountBtn:hover { opacity: 1; }" +
			"#accountTD .addAccountBtn > img { max-height: 40px; max-width: 40px; }" +
			"#accountTD .addAccountBtn > span { width: 90px; }" +
			"#accountTD .addAccountBtn > div { float: right; }" +
			// edit account;
			"#editAccountTD { display: none; position: relative; }" +
			"#editAccountTD .signInHeader img { position: relative; left: -34px; }" +
			"#editAccountTD .phholder { left: 0px; top: 0px; width: 100%; position: absolute; z-index: 5; cursor: text; }" +
			"#editAccountTD .alert-error { display: none; }" +
			"#editAccountCancel { background-color: #D11141; margin-left: 8px; }" +
			// password mask;
			".passMask { position: absolute; right: 8px; top: 8px; width: 16px; height: 16px; cursor: pointer; }";
		var stylesheet = document.createElement("style");
		stylesheet.type = "text/css";
		if (stylesheet.styleSheet) {
			stylesheet.styleSheet.cssText = css;
		} else {
			stylesheet.appendChild(document.createTextNode(css));
		}
		(document.head || document.getElementsByTagName("head")[0]).appendChild(
			stylesheet,
		);

		var accountTD = document.createElement("div");
		accountTD.id = "accountTD";

		var mainTD = document.getElementById("maincontent");
		mainTD.parentNode.insertBefore(accountTD, mainTD);

		function paint() {
			profiles.forEach(function (profile, i) {
				if (!profile.color) {
					profile.color =
						metroColors[
							(metroColorsIndex =
								++metroColorsIndex >= metroColors.length
									? 0
									: metroColorsIndex)
						];
					GM_setValue("MWLID.profiles", JSON.stringify(profiles));
				}
				var contrastDark = getContrastYIQ(profile.color);

				var profileDiv = document.createElement("div");
				profileDiv.classList.add(
					"profile",
					contrastDark ? "dark" : "light",
				);
				profileDiv.setAttribute("title", profile.mail);
				profileDiv.style.backgroundColor = profile.color;
				profileDiv.addEventListener(
					"click",
					proxy(function (_event, _profile) {
						document.getElementById("i0116").value = _profile.mail;
						fireEvent(document.getElementById("i0116"), "change");

						document.getElementById("i0118").value = _profile.pass;
						fireEvent(document.getElementById("i0118"), "change");

						if (autoLogin) {
							document.getElementById("idSIButton9").click();
						}
					}, profile),
				);

				var profileImg = document.createElement("img");
				profileImg.classList.add("profileImg");
				profileImg.setAttribute(
					"src",
					profile.photo ||
						profile.img ||
						(contrastDark ? image.photoDark : image.photoLight),
				);

				var profileName = document.createElement("span");
				profileName.classList.add("profileName");
				profileName.appendChild(document.createTextNode(profile.name));

				var profileManage = document.createElement("div");
				profileManage.classList.add("profileManage");

				if (i !== 0) {
					var profileManageLeft = document.createElement("img");
					profileManageLeft.setAttribute("title", "Move to the left");
					profileManageLeft.setAttribute(
						"src",
						contrastDark ? image.leftDark : image.leftLight,
					);
					profileManage.appendChild(profileManageLeft);
					profileManageLeft.addEventListener(
						"click",
						proxy(
							function (_event, _profile, _i) {
								_event.stopPropagation();

								var index = parseInt(_i, 10);

								if (
									parseInt(editAccountId.value, 10) === index
								) {
									editAccountId.value = index - 1;
								}

								var tmp = profiles[index];
								profiles[index] = profiles[index - 1];
								profiles[index - 1] = tmp;

								GM_setValue(
									"MWLID.profiles",
									JSON.stringify(profiles),
								);

								repaint();
							},
							profile,
							i,
						),
					);
				}

				if (i !== profiles.length - 1) {
					var profileManageRight = document.createElement("img");
					profileManageRight.setAttribute(
						"title",
						"Move to the right",
					);
					profileManageRight.setAttribute(
						"src",
						contrastDark ? image.rightDark : image.rightLight,
					);
					profileManage.appendChild(profileManageRight);
					profileManageRight.addEventListener(
						"click",
						proxy(
							function (_event, _profile, _i) {
								_event.stopPropagation();

								var index = parseInt(_i, 10);

								if (
									parseInt(editAccountId.value, 10) === index
								) {
									editAccountId.value = index + 1;
								}

								var tmp = profiles[index];
								profiles[index] = profiles[index + 1];
								profiles[index + 1] = tmp;

								GM_setValue(
									"MWLID.profiles",
									JSON.stringify(profiles),
								);

								repaint();
							},
							profile,
							i,
						),
					);
				}

				var profileManageEdit = document.createElement("img");
				profileManageEdit.setAttribute(
					"title",
					"Click to edit this account...",
				);
				profileManageEdit.setAttribute(
					"src",
					contrastDark ? image.editDark : image.editLight,
				);
				profileManage.appendChild(profileManageEdit);
				profileManageEdit.addEventListener(
					"click",
					proxy(
						function (_event, _profile, _i) {
							_event.stopPropagation();

							document.querySelector(
								"#maincontent > section",
							).style.display = "none";

							document.getElementById(
								"editAccountTD",
							).style.display = "block";

							setAccount(_i, _profile);
						},
						profile,
						i,
					),
				);

				var profileManageDelete = document.createElement("img");
				profileManageDelete.setAttribute(
					"title",
					"Delete this account!",
				);
				profileManageDelete.setAttribute(
					"src",
					contrastDark ? image.deleteDark : image.deleteLight,
				);
				profileManage.appendChild(profileManageDelete);
				profileManageDelete.addEventListener(
					"click",
					proxy(
						function (_event, _profile, _i) {
							_event.stopPropagation();

							if (
								window.confirm(
									"Are you sure you want to delete this account?",
								)
							) {
								profiles.splice(_i, 1);

								GM_setValue(
									"MWLID.profiles",
									JSON.stringify(profiles),
								);

								repaint();

								setAccount();
							}
						},
						profile,
						i,
					),
				);

				accountTD.appendChild(profileDiv);
				profileDiv.appendChild(profileImg);
				profileDiv.appendChild(profileName);
				profileDiv.appendChild(profileManage);
			});

			var addAccountBtnDiv = document.createElement("div");
			addAccountBtnDiv.classList.add("profile", "addAccountBtn");
			addAccountBtnDiv.setAttribute("title", "Add account");
			addAccountBtnDiv.style.backgroundColor = "#0072C6";
			addAccountBtnDiv.addEventListener("click", function () {
				document.querySelector("#maincontent > section").style.display =
					"none";

				document.getElementById("editAccountTD").style.display =
					"block";

				setAccount();
			});

			var addAccountBtnImg = document.createElement("img");
			addAccountBtnImg.classList.add("profileImg");
			addAccountBtnImg.setAttribute("src", image.addLight);

			var addAccountBtnName = document.createElement("span");
			addAccountBtnName.classList.add("profileName");
			addAccountBtnName.appendChild(
				document.createTextNode("Add account"),
			);

			accountTD.appendChild(addAccountBtnDiv);
			addAccountBtnDiv.appendChild(addAccountBtnImg);
			addAccountBtnDiv.appendChild(addAccountBtnName);
		}
		function repaint() {
			while (accountTD.hasChildNodes()) {
				accountTD.removeChild(accountTD.lastChild);
			}
			metroColorsIndex = -1;
			paint();
		}
		paint();

		var editAccountDiv = document.createElement("div");
		editAccountDiv.id = "editAccountTD";
		editAccountDiv.classList.add("floatLeft");
		editAccountDiv.innerHTML =
			'<div style="height: 40px;"></div>' +
			'<div id="i0272" class="signInHeader" style="height: 80px;">' +
			'<h1><img src="' +
			image.header +
			'" alt="Multiple Windows Live IDs" /></h1>' +
			"</div>" +
			'<input id="editAccountId" type="hidden" />' +
			"<div>" +
			"<div>" +
			'<div id="editAccountHeader1" class="row text-subheader">Add account</div>' +
			'<div id="editAccountHeader2" class="row text-subheader">Edit account</div>' +
			'<div class="form-group">' +
			'   <div class="placeholderContainer"><input id="editAccountName"  class="form-control" type="text"    /><div class="phholder"><div class="placeholder">Name</div></div></div></div>' +
			'<div class="form-group">' +
			'   <div class="alert alert-error" id="editAccountMailError">Please enter your email address in the format someone@example.com.</div>' +
			'   <div class="placeholderContainer"><input id="editAccountMail"  class="form-control" type="email"   /><div class="phholder"><div class="placeholder">someone@example.com</div></div></div></div>' +
			'<div class="form-group">' +
			'   <div class="alert alert-error" id="editAccountPassError">Please enter the password for your Microsoft account.</div>' +
			'   <div class="placeholderContainer"><input id="editAccountPass"  class="form-control" type="password"/><div class="phholder"><div class="placeholder">Password</div></div></div></div>' +
			'<div class="form-group">' +
			'   <div class="placeholderContainer"><input id="editAccountPhoto" class="form-control" type="text"    /><div class="phholder"><div class="placeholder">http://my.pictu.re/img.png</div></div></div></div>' +
			'<div class="form-group">' +
			'   <div class="placeholderContainer"><input id="editAccountColor" class="form-control" type="text"    /><div class="phholder"><div class="placeholder">#AB12CD</div></div></div></div>' +
			"</div>" +
			'<div class="section"><input id="editAccountSubmit" value="Submit" class="default" type="submit"/><input id="editAccountCancel" value="Cancel" class="default" type="submit"/></div>' +
			'<div class="section">Multiple Windows Live IDs. <a class="TextSemiBold" href="https://github.com/jerone/UserScripts/tree/master/Multiple_Windows_Live_IDs" target="_blank">More info...</a></div>' +
			"</div>";
		mainTD.appendChild(editAccountDiv);

		var editAccountHeader1 = document.getElementById("editAccountHeader1"),
			editAccountHeader2 = document.getElementById("editAccountHeader2"),
			editAccountId = document.getElementById("editAccountId"),
			editAccountName = document.getElementById("editAccountName"),
			editAccountMail = document.getElementById("editAccountMail"),
			editAccountPass = document.getElementById("editAccountPass"),
			editAccountPhoto = document.getElementById("editAccountPhoto"),
			editAccountColor = document.getElementById("editAccountColor"),
			editAccountMailError = document.getElementById(
				"editAccountMailError",
			),
			editAccountPassError = document.getElementById(
				"editAccountPassError",
			);

		addPlaceHolders(editAccountName);
		addPlaceHolders(editAccountMail);
		addPlaceHolders(editAccountPass);
		addPlaceHolders(editAccountPhoto);
		addPlaceHolders(editAccountColor);

		if (addPassMask) {
			addPassMaskFn(editAccountPass);
		}

		document
			.getElementById("editAccountSubmit")
			.addEventListener("click", function (e) {
				e.preventDefault();

				editAccountMailError.style.display = !editAccountMail.value
					? "block"
					: "none";
				editAccountPassError.style.display = !editAccountPass.value
					? "block"
					: "none";

				if (!editAccountPass.value || !editAccountMail.value) {
					return;
				}

				var index = parseInt(editAccountId.value, 10);
				profiles[index === -1 ? profiles.length : index] = {
					name: editAccountName.value,
					mail: editAccountMail.value,
					pass: editAccountPass.value,
					photo: editAccountPhoto.value,
					color: editAccountColor.value,
				};

				GM_setValue("MWLID.profiles", JSON.stringify(profiles));

				repaint();

				document.querySelector("#maincontent > section").style.display =
					"block";

				document.getElementById("editAccountTD").style.display = "none";

				setAccount();
			});

		document
			.getElementById("editAccountCancel")
			.addEventListener("click", function (e) {
				e.preventDefault();

				document.querySelector("#maincontent > section").style.display =
					"block";

				document.getElementById("editAccountTD").style.display = "none";

				setAccount();
			});

		function setAccount(id, profile) {
			profile = profile || {};

			editAccountHeader1.style.display = !id ? "block" : "none";
			editAccountHeader2.style.display = id ? "block" : "none";

			editAccountId.value = id != null ? id : -1;
			editAccountName.value = profile.name || "";
			editAccountMail.value = profile.mail || "";
			editAccountPass.value = profile.pass || "";
			editAccountPhoto.value = profile.photo || profile.img || "";
			editAccountColor.value =
				profile.color ||
				metroColors[profiles.length % metroColors.length];

			fireEvent(editAccountName, "change");
			fireEvent(editAccountMail, "change");
			fireEvent(editAccountPass, "change");
			fireEvent(editAccountPhoto, "change");
			fireEvent(editAccountColor, "change");

			editAccountMailError.style.display = "";
			editAccountPassError.style.display = "";

			editAccountName.focus();
		}

		function addPlaceHolders(elm) {
			elm.parentNode
				.getElementsByClassName("phholder")[0]
				.addEventListener("mouseup", function () {
					elm.focus();
				});
			addEventListeners(
				elm,
				["change", "keyup", "keydown", "keypress"],
				function () {
					elm.parentNode.getElementsByClassName(
						"phholder",
					)[0].style.display = !elm.value ? "block" : "none";
				},
			);
		}

		function addPassMaskFn(elm) {
			var img = document.createElement("img");
			img.classList.add("passMask");
			img.setAttribute("src", image.passMask);
			img.setAttribute("title", "Click to hide/show the password");
			img.style.display = elm.value ? "block" : "none";
			img.addEventListener("click", function () {
				elm.setAttribute(
					"type",
					elm.getAttribute("type") === "password"
						? "text"
						: "password",
				);
			});
			addEventListeners(
				elm,
				["change", "keyup", "keydown", "keypress"],
				function () {
					img.style.display = elm.value ? "block" : "none";
				},
			);
			elm.parentNode.insertBefore(img, elm.nextSibling);
		}

		if (addPassMask) {
			addPassMaskFn(document.getElementById("i0118")); // Microsoft password;
		}
	}, 500);
})();