Skip to content

Instantly share code, notes, and snippets.

@Mygod
Last active August 29, 2015 14:07
Show Gist options
  • Save Mygod/cd6efc1524d3f1662b25 to your computer and use it in GitHub Desktop.
Save Mygod/cd6efc1524d3f1662b25 to your computer and use it in GitHub Desktop.
A buggy WordPress exporter (it's buggy, don't use it)
(s = document.createElement('script')).setAttribute('src', 'https://mygod.tk/js/jquery/jquery-2.0.3.min.js');
document.getElementsByTagName('head')[0].appendChild(s);
(s = document.createElement('script')).setAttribute('src', 'https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js');
document.getElementsByTagName('head')[0].appendChild(s);
output = [];
itemCount = [];
processedCount = [];
count = (q = $('a[href^="*wordpress*/?p="]')).length;
processed = 0;
function process(data) {
$('li.comment-author-86 div[id^="commentbody-"]', r = $.parseHTML(data)).each(function() {
output.push($(this).text().trim() + '\r\n\r\n~~~\r\n\r\n');
});
return r;
}
q.each(function () {
if (itemCount[i = /\d+/.exec($(this).attr('href'))[0]] != undefined) {
console.log(++processed + '/' + count);
return;
}
itemCount[i] = 0;
$.get(a = '*wordpress*/?p=' + i, function (data) {
processedCount[i] = 1;
if ((itemCount[i] = $('span.page-numbers', process(data)).text()) <= 1) console.log(++processed + '/' + count);
else for (page = 1; page < itemCount[i]; ++page) $.get(a + '&cpage=' + page, function (data) {
process(data);
if (itemCount[i] == ++processedCount[i]) console.log(++processed + '/' + count);
});
});
});
setTimeout(function () {
if (processed >= count) saveAs(new Blob(output, { type: 'text/plain; charset=utf-8' }), "exported.txt");
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment