Created
January 23, 2014 10:43
-
-
Save isorna/8576532 to your computer and use it in GitHub Desktop.
Export to CSV with javascript from WordPress site's listing
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
// 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