Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imasimali/c5a5226226281baec01566a42243370f to your computer and use it in GitHub Desktop.
Save imasimali/c5a5226226281baec01566a42243370f to your computer and use it in GitHub Desktop.
Browser JavaScript to export contacts data from google shared domain contacts directory. When export is turned off by administrator.
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
window.contactsData = new Set();
window.scroller =
document.querySelectorAll(
".ZvpjBb.C8Dkz"
)[0].parentElement.parentElement.parentElement.parentElement.parentElement;
while (scroller.scrollHeight - scroller.scrollTop > 400) {
for (let element of document
.querySelectorAll(".ZvpjBb.C8Dkz")[0]
.querySelectorAll(".XXcuqd")) {
if (element.firstChild.childNodes.length == 1) {
break;
}
let image = element.firstChild.childNodes[0].childNodes[1].src;
let name = element.firstChild.childNodes[1].innerText;
let email = element.firstChild.childNodes[2].innerText;
let phone = element.firstChild.childNodes[3].innerText;
window.contactsData.add(
JSON.stringify({ name: name, email: email, image: image, phone: phone })
);
}
scroller.scrollTo({
top: scroller.scrollTop + 400,
behavior: "smooth",
});
console.log(
"Completed iteration;",
scroller.scrollTop.toString() +
"/" +
scroller.scrollHeight.toString() +
" = " +
((scroller.scrollTop / scroller.scrollHeight) * 100).toString() +
"%"
);
await sleep(1000);
}
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], { type: contentType });
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
const jsonData = JSON.parse(JSON.stringify(Array.from(contactsData)));
download(jsonData, "data.json", "text/plain");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment