Skip to content

Instantly share code, notes, and snippets.

@lekevicius
Created January 6, 2013 17:02
Show Gist options
  • Save lekevicius/4468634 to your computer and use it in GitHub Desktop.
Save lekevicius/4468634 to your computer and use it in GitHub Desktop.
Download all IconMonstr icons (previous website version; might need modification to work on new design).
loadPage = (url) ->
casper.open(url).then ->
pageIcons = @evaluate ->
links = []
$('a.thumbnail_link').each -> links.push $(@).attr('href')
links
# console.log pageIcons
allIcons.push icon for icon in pageIcons
hasNextPage = @evaluate -> $('.navigation a.next').length
# console.log hasNextPage
if hasNextPage
nextPageURL = @evaluate -> $('.navigation a.next').attr('href')
console.log nextPageURL
loadPage nextPageURL
else
console.log allIcons
downloadIcons()
downloadIcon = (url) ->
console.log url
casper.then ->
casper.open(url).then ->
pngURL = @evaluate -> $('a.download_png').attr('href')
svgURL = @evaluate -> $('a.download_svg').attr('href')
fileName = url.substr 22, url.length - 28
console.log fileName
console.log pngURL
console.log svgURL
casper.download(pngURL, fileName + '.png')
casper.download(svgURL, fileName + '.svg')
downloadIcons = ->
for icon in allIcons
downloadIcon icon
casper = require('casper').create
verbose: true
logLevel: "debug"
clientScripts: ["jquery.js"]
allIcons = []
casper.start().then ->
loadPage 'http://iconmonstr.com/'
casper.run ->
@echo 'Completed'
@exit()
@illmat
Copy link

illmat commented Nov 7, 2013

Found this and rewrote it for my needs: https://gist.github.com/illmat/7355599
Thanks for pushing me into casperjs ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment