Skip to content

Instantly share code, notes, and snippets.

@tqk2811
Last active June 15, 2023 09:12
Show Gist options
  • Save tqk2811/90bd180e574f82ed7c47990825e294b0 to your computer and use it in GitHub Desktop.
Save tqk2811/90bd180e574f82ed7c47990825e294b0 to your computer and use it in GitHub Desktop.
AutoLoginGoogleExt
chrome.runtime.onMessage.addListener(function (message, sender, callback) {
if (message && message == "close_tab_call") {
chrome.tabs.remove(sender.tab.id, function () {});
}
});
var g_acc = {
email: "{email}",
pass: "{pass}",
recovery: "{recovery}"
};
var step = 0;
var timeout = Number("{timeout}");
var intervalTime = Number("{intervalTime}");
window.addEventListener('load', function () {
window.setInterval(RunLogin, intervalTime);
window.setTimeout(closeChrome, timeout);
if (window.location.href.includes("myaccount.google.com")) closeChrome();
if (!window.location.href.includes("accounts.google.com")) closeChrome();
});
function RunLogin() {
switch (step) {
case 0: {
if (document.body.innerHTML.includes(g_acc.email)) {
step = -1;
closeChrome();
}
let email = document.querySelector("input[id='identifierId']");
let btn_emailnext = document.querySelector("[id='identifierNext'] button");
if (email && btn_emailnext && !isHidden(email)) {
email.value = g_acc.email;
btn_emailnext.click();
step++;
}
break;
}
case 1: {
let pass = document.querySelector("input[name='password']");
let btn_passnext = document.querySelector("[id='passwordNext'] button");
if (pass && btn_passnext && !isHidden(pass)) {
pass.value = g_acc.pass;
btn_passnext.click();
step++;
}
break;
}
case 2: {
let recs = document.querySelectorAll("div[jsname='EBHGs']:not([id])");
if (recs.length != 0) {
recs[recs.length - 1].click();
step++;
}
else {
let rec_mail = document.querySelector("input[id='knowledge-preregistered-email-response']");
if(rec_mail && !isHidden(rec_mail)){
step++;
}
}
break;
}
case 3: {
let rec_mail = document.querySelector("input[id='knowledge-preregistered-email-response']");
let rec_mail_next = document.querySelector("button[jsname='LgbsSe']");
if (rec_mail && rec_mail_next && !isHidden(rec_mail)) {
rec_mail.value = g_acc.recovery;
rec_mail_next.click();
step++;
}
break;
}
}
}
function closeChrome() {
chrome.runtime.sendMessage("close_tab_call");
}
function isHidden(el) {
return (el.offsetParent === null)
}
{
"name": "Auto Login Google",
"description": "Auto Login Google.",
"version": "0.0.1",
"permissions": [
"<all_urls>",
"activeTab",
"tabs"
],
"background": {
"scripts": [
"/background.js"
],
"persistent": true
},
"manifest_version": 2,
"content_scripts": [
{
"run_at": "document_idle",
"matches": [
"https://*.google.com/*"
],
"js": [
"/inject.js"
]
}
]
}
@raishid
Copy link

raishid commented Mar 24, 2021

can you explain how it is used?

@tqk2811
Copy link
Author

tqk2811 commented Mar 25, 2021

using string replace to put account info in inject.js

var g_acc =
{
	email : "{email}",
	pass : "{pass}",
	recovery : "{recovery}"
};
var timeout = Number("{timeout}");//60000 mili
var intervalTime = Number("{intervalTime}");//500 mili

Write 3 file to a folder ( extPath )
Open chrome with argument (not selenium), and just wait process exit
string argument = $"--load-extension=\"{extPath}\" --user-data-dir=\"{profilePath}\" \"https://accounts.google.com/\"";

And then reopen chrome with selenium

@mytran1998
Copy link

Thanks sir

@NguyenAnHuy
Copy link

Có hướng dẫn chi tiết không bạn? Tôi không phải dân IT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment