Last active
August 26, 2019 00:56
-
-
Save CVertex/82a982cfcba5eb1db5079a16d5051d1b to your computer and use it in GitHub Desktop.
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
async function getLoggedInEmail() { | |
return new Promise((resolve, reject) => { | |
try { | |
// header element works on gmail | |
// .ongoogle-material-minibar works on slides UI | |
let header = document.querySelector('header'); | |
if (header === null) { | |
// Try mini-bar | |
header = document.querySelector('.onegoogle-material-minibar') | |
} | |
header | |
.querySelectorAll('a[aria-label]') | |
.forEach((el) => { | |
let pattern = /Google Account:.*\n\((.*@.*)\)/ | |
let ariaLabel = el.getAttribute('aria-label'); | |
if (pattern.test(ariaLabel)) { | |
const email = pattern.exec(ariaLabel)[1] | |
// console.log(`Logged in email is : ${email}`); | |
resolve(email); | |
} | |
}); | |
} catch (error) { | |
reject(error); | |
} | |
}); | |
} | |
getLoggedInEmail().then(email =>console.log(`Logged in email is : ${email}`)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment