Skip to content

Instantly share code, notes, and snippets.

@lajlev
Forked from illmat/iconMonster.js
Created November 30, 2018 09:28
Show Gist options
  • Save lajlev/273f848a2edd055b40950f57e8267c56 to your computer and use it in GitHub Desktop.
Save lajlev/273f848a2edd055b40950f57e8267c56 to your computer and use it in GitHub Desktop.
Doesn't actually download anything, but saves all svgs from Iconmonstr by grabbing each inline svg from the preview box. If you like the Icons please consider to make a donation for the iconmostr wesbite - http://iconmonstr.com/
var casper = require('casper').create();
var fs = require('fs');
var pages = [];
casper.start('http://iconmonstr.com/page/2', function () {
var pageNumbers = this.evaluate(function () {
return $('a.page-numbers:nth-child(7)').html();
});
for (var i = 1; i <= pageNumbers; i++) {
pages.push('http://iconmonstr.com/page/' + i);
}
this.each(pages, function (self, page) {
self.thenOpen(page, function () {
this.echo(this.getCurrentUrl());
var fileNames = this.evaluate(function () {
var tempArray = [];
$('.thumbnail-link').each(function () {
var name = $(this).attr('href').substring(22);
name = name.substring(0, name.length - 1);
tempArray.push(name + '.svg');
});
return tempArray;
});
var inlineSvgs = this.evaluate(function () {
var tempArray = [];
$('.thumbnail-preview').each(function () {
tempArray.push($(this).html());
});
return tempArray;
});
for (var i = 0; i < fileNames.length; i++) {
inlineSvgs[i] = '<?xml version="1.0" encoding="utf-8"?>\n' +
'<!-- License Agreement at http://iconmonstr.com/license/ -->\n' +
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
inlineSvgs[i];
fs.write('svg/' + fileNames[i], inlineSvgs[i], 'w');
}
});
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment