Commit 1f5a1271 authored by insert's avatar insert 🎺

Inject elements instead of rely on console

parent f8a8c4d5
......@@ -6,7 +6,7 @@
// @author insert
// @match https://contacts.google.com/*
// @grant none
// @run-at document-start
// @run-at document-end
// ==/UserScript==
/**
......@@ -18,48 +18,65 @@
* 1. Go to Google Contacts
* 2. Run script
* 3. Collect data by scrolling and loading all contacts
* 4. Run collect(); to get data set
* 4. Press button at the top of the site
*/
let set = {};
(() => {
document.onreadystatechange = function () {
if (document.readyState === "complete") {
(() => {
var targetNode = document.querySelector("#yDmH0d");
var observerOptions = {
childList: true,
attributes: false,
subtree: true
};
var targetNode = document.querySelector("#yDmH0d");
var observerOptions = {
childList: true,
attributes: false,
subtree: true
};
let callback = (mutationList, observer) => {
mutationList.forEach((mutation) => {
switch (mutation.type) {
case 'childList':
mutation.addedNodes.forEach(x => {
if (x.className == "XXcuqd") {
let p = x.innerText;
if (p.startsWith('\t')) p = p.substring(1);
let r = p.split('\t');
set[r[0]] = r[1];
}
});
break;
}
});
};
let callback = (mutationList, observer) => {
mutationList.forEach((mutation) => {
switch (mutation.type) {
case 'childList':
mutation.addedNodes.forEach(x => {
if (x.className == "XXcuqd") {
let p = x.innerText;
if (p.startsWith('\t')) p = p.substring(1);
let r = p.split('\t');
set[r[0]] = r[1];
}
});
break;
}
});
};
var observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
var observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
})();
})();
function collect() {
let d = new Date();
return JSON.stringify({
_comment: "Generated using Google Contacts scraper script [v1].",
year: d.getMonth() > 7,
generated: '' + d,
data: set
});
function collect() {
let d = new Date();
return JSON.stringify({
_comment: "Generated using Google Contacts scraper script [v1].",
year: d.getMonth() > 7,
generated: '' + d,
data: set
});
}
(() => {
let el = document.createElement('a');
el.innerText = "click to export and console.log data set";
el.addEventListener('click', () => {
console.log(collect());
return false;
});
document.querySelector('.gb_ne').append(el);
})();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment