Skip to content

Instantly share code, notes, and snippets.

@isorna
Created January 23, 2014 10:43
Show Gist options
  • Save isorna/8576532 to your computer and use it in GitHub Desktop.
Save isorna/8576532 to your computer and use it in GitHub Desktop.
Export to CSV with javascript from WordPress site's listing
// Filter and export site's listing data
// columns: 'Domain', 'Parent Theme', 'Bootstrap', 'Mobile Version', 'Data Integration'
if (jQuery('body').hasClass('sites-php')) {
var aCSVData = [], cOutput = '', cURI = '';
jQuery('#the-list tr:not(.site-deleted)').each(function () {
var aTMP = [], cTMP = '', cTMP2 = '';
cTMP = jQuery('.blogname a', this).html().replace(/"/g, '""');
aTMP.push('"' + cTMP + '"');
cTMP = jQuery('.column-site_data p.site-template', this).text();
if (cTMP.indexOf('Tema padre:') >= 0) {
cTMP2 = cTMP.split(': ')[1];
} else {
cTMP2 = 'no';
}
aTMP.push('"' + cTMP2.replace(/"/g, '""') + '"');
cTMP = jQuery('.column-site_data p.site-bootstrap', this).text();
if (cTMP.indexOf('¿Bootstrap?:') >= 0) {
cTMP2 = cTMP.split(': ')[1].toLowerCase();
} else {
cTMP2 = 'no';
}
aTMP.push('"' + cTMP2.replace(/"/g, '""') + '"');
cTMP = jQuery('.column-site_data p.site-mobile', this).text();
if (cTMP.indexOf('Versión móvil:') >= 0) {
cTMP2 = cTMP.split(': ')[1].toLowerCase();
} else {
cTMP2 = 'no';
}
aTMP.push('"' + cTMP2.replace(/"/g, '""') + '"');
cTMP = jQuery('.column-site_data p.site-content-integration', this).text();
if (cTMP.indexOf('¿Integración de contenidos activa?:') >= 0) {
cTMP2 = cTMP.split(': ')[1].toLowerCase();
} else {
cTMP2 = 'no';
}
aTMP.push('"' + cTMP2.replace(/"/g, '""') + '"');
aCSVData.push(aTMP.join(','));
});
cOutput = aCSVData.join('\n');
cURI = 'data:application/csv;charset=UTF-8,' + encodeURIComponent(cOutput);
jQuery('#doaction').after('<a id="table2csvlink" href="' + cURI + '" download="sites.csv">download .csv</a>');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment