Skip to content

Instantly share code, notes, and snippets.

@hubgit
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hubgit/8954235 to your computer and use it in GitHub Desktop.
Save hubgit/8954235 to your computer and use it in GitHub Desktop.
Generate a list of files from Google search results
// localStorage.setItem('files-xls', null)
var lines = JSON.parse(localStorage.getItem('files-xls')) || [];
var links = Array.prototype.slice.call(document.querySelectorAll('a'));
links.map(function(link) {
return link.getAttribute('data-href') || link.getAttribute('href');
}).filter(function(href) {
return href && href.match(/\.xls$/);
}).forEach(function(href) {
lines.push(href);
});
localStorage.setItem('files-xls', JSON.stringify(lines));
var next = false;
links.forEach(function(link) {
if (link.textContent == 'Next') {
next = link;
}
});
if (next) {
next.click();
} else {
var blob = new Blob([lines.join('\n')], { type: 'text/csv' });
window.location.href = URL.createObjectURL(blob);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment