Skip to content

Instantly share code, notes, and snippets.

@wmbest2
Created September 25, 2009 15:38
Show Gist options
  • Save wmbest2/193630 to your computer and use it in GitHub Desktop.
Save wmbest2/193630 to your computer and use it in GitHub Desktop.
// Replace inline Images with Links
if (settings.replaceImagesWithLinks == 'true') {
jQuery('.postbody img').each(function() {
var source = jQuery(this).attr('src');
jQuery(this).after("<a href='" + source + "'>" + source + "</a>");
jQuery(this).remove();
});
}
// Replace Links with Images
if (settings.replaceLinksWithImages == 'true') {
jQuery('.postbody a').each(function() {
console.log(jQuery(this).parents());
if((settings.dontReplaceLinksSpoiler != 'true' || jQuery(this).parents('.bbs-spoiler') != null) ) {
var match = jQuery(this).attr('href').match(/https?\:\/\/(?:[-_0-9a-zA-Z]+\.)+[a-z]{2,6}(?:\/[^/#?]+)+\.(?:jpe?g|gif|png|bmp)/);
if(match != null) {
jQuery(this).after("<img src='" + match[0] + "' />");
jQuery(this).remove();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment