Created
April 28, 2024 14:55
-
-
Save porobertdev/0aa8f1f51a7a0a315593508805d2f688 to your computer and use it in GitHub Desktop.
google-myactivity-exporter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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