Last active
April 4, 2024 21:58
-
-
Save Brayyy/09d01cb4ef27d5d09a2243553e624481 to your computer and use it in GitHub Desktop.
UserScript - ExtremeReach auto-login
This file contains 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.4.1 | |
// @description Automatically login to ER using Google providor | |
// @author balmini@extremereach.com | |
// @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 Google) | |
while (true) { | |
await setTimeoutP(250); | |
setStatus("looking for providers"); | |
let found = false; | |
try { | |
// Iterate children, finding the Google 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 === "Google") { | |
// setStatus(`${i} "Google" === ${textContent}`); | |
// child.style.setProperty("background-color", "#3b5368", "important"); | |
child.click(); | |
found = true; | |
} else { | |
// setStatus(`${i} "Google" !== ${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