Skip to content

Instantly share code, notes, and snippets.

@Syakhisk
Created November 27, 2023 06:37
Show Gist options
  • Save Syakhisk/84a810a8180747491d915f088c964e37 to your computer and use it in GitHub Desktop.
Save Syakhisk/84a810a8180747491d915f088c964e37 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Google SSO Account Picker
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://accounts.google.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=accounts.google.com
// @grant none
// @run-at document-end
// @noframes
// ==/UserScript==
function main() {
const myEmail = "syakhisk.syari@gojek.com";
const patterns = [
/https?:\/\/wd3\.myworkday\.com\/gojek/,
/https?:\/\/accounts\.google\.com\/o\/saml2\/idp/,
];
const elements = Array.from(document.querySelectorAll(`[data-authuser]`));
const el = elements.find((e) => e.dataset.identifier == myEmail);
if (!el) {
console.log("TamperMonkey: Account not found");
return;
}
const url = new URL(window.location.href);
const redirectUri = url.searchParams.get("redirect_uri");
const continueParams = url.searchParams.get("continue");
for (let p of patterns) {
if (!p.test(redirectUri) && !p.test(continueParams)) continue;
console.log("TamperMonkey: Matched: " + redirectUri);
const isBusy = document.querySelector(
'div[role="presentation"][tabindex="-1"]',
);
const hasBackButton = document.querySelector('div[role="button"]#next');
if (isBusy) {
console.log("Page is busy...");
}
// Close page if there was "unknown error"
if (hasBackButton) {
window.close();
}
// Try clicking until page gets busy
if (!isBusy) {
console.log("Clicking...");
console.log(el);
el.click();
}
}
}
(async function () {
"use strict";
console.log("TamperMonkey: Running...");
await new Promise((resolve) => setTimeout(resolve, 500));
setInterval(main, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment