Skip to content

Instantly share code, notes, and snippets.

@daformat
Last active August 29, 2015 14:01
Show Gist options
  • Save daformat/cfca3b29324ac9891f19 to your computer and use it in GitHub Desktop.
Save daformat/cfca3b29324ac9891f19 to your computer and use it in GitHub Desktop.
Extract images from current wikipedia page to markdown.
(function(){
var $t = $('.thumbcaption'),
$i =$('.image img'),
r="", md, i;
for(i=0; i < $t.length; i++){
r+=("![" + $($t[i]).text().replace(/(\r\n|\n|\r)/gm,"")+"]("+$($i[i]).attr('src').replace(/(\/thumb\/)/gm, "/").replace(/\.(png|svg|jpg|jpeg|bmp|gif)\/.*$/gm, ".$1")+")\n" )
}
md = r+'\nImages from ["'+$('#firstHeading').text()+'" on wikipedia]'+'('+document.location.href+')\n';
console.log('\n\nFound '+$i.length+' image'+($i.length>1?'s':'')+', here is the markdown:\n-----\n\n'+md+'\n');
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment