Last active
October 3, 2024 16:55
-
-
Save Brayyy/09d01cb4ef27d5d09a2243553e624481 to your computer and use it in GitHub Desktop.
UserScript - ExtremeReach auto-login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ER auto-login | |
// @namespace https://github.com/Brayyy | |
// @version 1.5.0 | |
// @description Automatically login to ER using Microsoft providor | |
// @author [email protected] | |
// @match https://app.extremereach.com/Login* | |
// @match https://app.dev-extremereach.com/Login* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=extremereach.com | |
// @updateURL https://gist.github.com/Brayyy/09d01cb4ef27d5d09a2243553e624481/raw/ER%2520auto-login.user.js | |
// @downloadURL https://gist.github.com/Brayyy/09d01cb4ef27d5d09a2243553e624481/raw/ER%2520auto-login.user.js | |
// @grant none | |
// ==/UserScript== | |
// To unset the user name, run this in the console: | |
// localStorage.removeItem("erAutoLoginUserName"); | |
(async function() { | |
'use strict'; | |
const setTimeoutP = ms => new Promise(r => { setTimeout(r, ms); }); | |
const setStatus = (status) => { | |
console.log(`ER_AUTO_LOGIN: ${status}`); | |
// Page as of 2024-04-04 | |
try { | |
document.querySelector(".ceros-experience").parentElement.innerText = `ER auto-login ${status}`; | |
} catch (e) {} | |
// Page in dev as of 2024-04-04 | |
try { | |
document.querySelector(".xr-login-form-container").children[0].innerText = `ER auto-login: ${status}`; | |
} catch (e) {} | |
}; | |
setStatus("init..."); | |
// Read user name from local storage | |
let userName = localStorage.getItem("erAutoLoginUserName"); | |
// If no username found, show a prompt, asking for the user name | |
if (userName) { | |
setStatus("found user name in local storage"); | |
} else { | |
setStatus("no user name found in local storage"); | |
userName = prompt("ER auto-login: enter email you with to login with"); | |
// Validate the user name ends with @extremereach.com | |
if (!userName.endsWith("@extremereach.com")) { | |
alert("ER auto-login: invalid user name, must end with @extremereach.com"); | |
setStatus("invalid user name, must end with @extremereach.com. To try again, reload this page."); | |
return; | |
} | |
localStorage.setItem("erAutoLoginUserName", userName); | |
} | |
// Set the user name in the input box | |
document.getElementById("userName").value = userName; | |
await setTimeoutP(250); | |
setStatus("user name set, clicking nextButton..."); | |
// Click the button | |
document.getElementById("nextButton").click(); | |
setStatus("nextButton clicked"); | |
// This is needed if there are multiple providers configured (not just defaulting to Microsoft) | |
while (true) { | |
await setTimeoutP(250); | |
setStatus("looking for providers"); | |
let found = false; | |
try { | |
// Iterate children, finding the Microsoft button | |
const { children } = document.getElementById("providers"); | |
setStatus(`found ${children.length} providers`); | |
if (children.length === 0) { | |
continue; | |
} | |
for (let i = 0; i < children.length; i++) { | |
const child = children[i]; | |
const textContent = child.textContent; | |
if (textContent === "Microsoft") { | |
setStatus(`${i} "Microsoft" === ${textContent}`); | |
child.style.setProperty("background-color", "#7b93a8", "important"); | |
child.click(); | |
found = true; | |
} else { | |
// setStatus(`${i} "Microsoft" !== ${textContent}`); | |
} | |
} | |
if (found) { | |
setStatus("Awaiting login"); | |
break; | |
} | |
} catch (e) { | |
setStatus("login... no providors"); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment