Skip to content

Instantly share code, notes, and snippets.

@spra85
Last active May 20, 2016 15:11
Show Gist options
  • Save spra85/f07158947ecbbf7841d55a6ede4d9a6b to your computer and use it in GitHub Desktop.
Save spra85/f07158947ecbbf7841d55a6ede4d9a6b to your computer and use it in GitHub Desktop.
var body = $('body');

var paragraphs = body.find('p');

var adCounter = 0;
var adsPlaced = 0;
for (var i =0; i < paragraphs.length; i++) {
	var wordLength = _.words($(paragraphs[i]).html()).length;
  console.log(wordLength);
  $(paragraphs[i]).prepend('<h4>' + wordLength + '</h4>');
  adCounter = adCounter + wordLength;
  
  if (adCounter > 350 && adsPlaced < 3) {
  	// Place 'ad' here
  	  $(paragraphs[i]).append('<img src="//placehold.it/300x250">');
  	adCounter = 0;
    adsPlaced++;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment