Commit 1f5a1271 authored by insert's avatar insert 🎺

Inject elements instead of rely on console

parent f8a8c4d5
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// @author insert // @author insert
// @match https://contacts.google.com/* // @match https://contacts.google.com/*
// @grant none // @grant none
// @run-at document-start // @run-at document-end
// ==/UserScript== // ==/UserScript==
/** /**
...@@ -18,48 +18,65 @@ ...@@ -18,48 +18,65 @@
* 1. Go to Google Contacts * 1. Go to Google Contacts
* 2. Run script * 2. Run script
* 3. Collect data by scrolling and loading all contacts * 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 = {}; let set = {};
(() => { document.onreadystatechange = function () {
if (document.readyState === "complete") {
(() => {
var targetNode = document.querySelector("#yDmH0d"); var targetNode = document.querySelector("#yDmH0d");
var observerOptions = { var observerOptions = {
childList: true, childList: true,
attributes: false, attributes: false,
subtree: true subtree: true
}; };
let callback = (mutationList, observer) => { let callback = (mutationList, observer) => {
mutationList.forEach((mutation) => { mutationList.forEach((mutation) => {
switch (mutation.type) { switch (mutation.type) {
case 'childList': case 'childList':
mutation.addedNodes.forEach(x => { mutation.addedNodes.forEach(x => {
if (x.className == "XXcuqd") { if (x.className == "XXcuqd") {
let p = x.innerText; let p = x.innerText;
if (p.startsWith('\t')) p = p.substring(1); if (p.startsWith('\t')) p = p.substring(1);
let r = p.split('\t'); let r = p.split('\t');
set[r[0]] = r[1]; set[r[0]] = r[1];
} }
}); });
break; break;
} }
}); });
}; };
var observer = new MutationObserver(callback); var observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions); observer.observe(targetNode, observerOptions);
})(); })();
function collect() { function collect() {
let d = new Date(); let d = new Date();
return JSON.stringify({ return JSON.stringify({
_comment: "Generated using Google Contacts scraper script [v1].", _comment: "Generated using Google Contacts scraper script [v1].",
year: d.getMonth() > 7, year: d.getMonth() > 7,
generated: '' + d, generated: '' + d,
data: set 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