Skip to content

Instantly share code, notes, and snippets.

@porobertdev
Created April 28, 2024 14:55
Show Gist options
  • Save porobertdev/0aa8f1f51a7a0a315593508805d2f688 to your computer and use it in GitHub Desktop.
Save porobertdev/0aa8f1f51a7a0a315593508805d2f688 to your computer and use it in GitHub Desktop.
google-myactivity-exporter
function getSearchCount() {
const searches = document.querySelectorAll(
'c-wiz[jsrenderer="ZK8B7d"] div[role="list"] c-wiz'
);
console.log('');
console.warn(`Searches this week: ${searches.length}`);
const results = [];
searches.forEach((search) => {
const term =
search.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].textContent.replace(
'Searched for ',
''
);
results.push(term);
});
// print to the console too
console.log(results.join('\n'));
console.warn('you have 4s to focus the webpage');
setTimeout(
() =>
new Promise((resolve, reject) => {
if (document.hasFocus()) {
resolve(true);
} else {
reject('webpage was not focused');
}
}).then(
(success) => {
copyToClipboard(results.join('\n'));
alert('Searches history was copied to clipboard!');
},
(error) => {
console.error(error);
}
),
4000
);
}
function copyToClipboard(text) {
navigator.clipboard.writeText(text);
}
getSearchCount();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment