Last active
August 29, 2015 13:56
-
-
Save hubgit/8954235 to your computer and use it in GitHub Desktop.
Generate a list of files from Google search results
This file contains 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
// 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