Behance - fetch lazy-load images immediately

Fetch lazy-load images immediately at document load

目前为 2015-04-26 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Behance - fetch lazy-load images immediately
  3. // @description Fetch lazy-load images immediately at document load
  4. // @include https://www.behance.net/*
  5. // @version 1.03
  6. // @namespace wOxxOm.scripts
  7. // @author wOxxOm
  8. // @run-at document-start
  9. // ==/UserScript==
  10.  
  11. window.addEventListener('DOMContentLoaded', function(e) {
  12. var placeholders = document.querySelectorAll('.js-picture-lazy');
  13. for (var i=0, len=placeholders.length, p, img; i<len && (p=placeholders[i]); i++) {
  14. if (img = p.querySelector('img')) {
  15. img.src = img.dataset.src;
  16. img.removeAttribute('width');
  17. img.removeAttribute('height');
  18. img.removeAttribute('style');
  19. }
  20. var picture = document.createElement('picture');
  21. while (p.firstElementChild)
  22. picture.appendChild(p.removeChild(p.firstElementChild));
  23. p.parentNode.replaceChild(picture, p);
  24. p.remove();
  25. }
  26. });