Created
October 7, 2017 18:47
-
-
Save AlexR1712/01835f72cfdddc9d78478b82b513645b to your computer and use it in GitHub Desktop.
Tumblr Post type Text, thumbnails
This file contains hidden or 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
/* Created by AlexR1712 */ | |
function getImg (str) { | |
var m, | |
urls = [], | |
rex = /<img[^>]+src="(http:\/\/[^">]+)"/g; | |
while ( m = rex.exec( str ) ) { | |
urls.push( m[1] ); | |
} | |
return urls; | |
} | |
var posts = document.querySelectorAll('.post-excerpt'); | |
posts.forEach(function(body) { | |
imgs = getImg(body.innerHTML); | |
/* remove html tags */ | |
body.innerHTML = body.textContent; | |
if (imgs.length > 0) { | |
/* Set first image as default in view*/ | |
body.parentElement.parentElement.childNodes[0].src = imgs.shift(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment