Behance - fetch lazy-load images immediately

Fetch lazy-load images immediately at document load

As of 2015-04-26. See the latest version.

// ==UserScript==
// @name        Behance - fetch lazy-load images immediately
// @description Fetch lazy-load images immediately at document load
// @include     https://www.behance.net/*
// @version     1.03
// @namespace   wOxxOm.scripts
// @author      wOxxOm
// @run-at      document-start
// ==/UserScript==

window.addEventListener('DOMContentLoaded', function(e) {
  var placeholders = document.querySelectorAll('.js-picture-lazy');
  for (var i=0, len=placeholders.length, p, img; i<len && (p=placeholders[i]); i++) {
    if (img = p.querySelector('img')) {
      img.src = img.dataset.src;
      img.removeAttribute('width');
      img.removeAttribute('height');
      img.removeAttribute('style');
    }
    var picture = document.createElement('picture');
    while (p.firstElementChild)
      picture.appendChild(p.removeChild(p.firstElementChild));
    p.parentNode.replaceChild(picture, p);
    p.remove();
  }
});