APP分享抓取网页图片

var getShareImages = {
    defaultimg:"defaultimg.png",
    _allImgs:null,
    init:function(){
        getShareImages._allImgs = document.getElementsByTagName("img");
        if(getShareImages._allImgs.length == 0){                    
            return getShareImages.defaultimg;
        }else{
            return getShareImages.checkRepeat();
        }
    },
    _srcs:{},
    allImgs:[],
    checkRepeat:function(){
        var len = getShareImages._allImgs.length;
        for (var i = 0; i < len; i++) {
            var _img = getShareImages._allImgs[i];
              // 过滤掉不可以见的图片
              if(_img.style.display == ‘none‘ || _img.style.visibility == ‘hidden‘){
                  continue;
              }

              if(getShareImages._srcs[_img.src]){

              }else{
                  getShareImages._srcs[_img.src] = 1;
                  getShareImages.allImgs.push(_img);
              }
        };
        return getShareImages.checkCondition();

    },
    results:[],
    checkCondition:function(){
        var len = getShareImages.allImgs.length;
        var img;
        var loadedCount = 0;
        for (var i = 0; i < len && i < 10; i++) {
            img = getShareImages.allImgs[i];
            if(img.width >= 200 || img.height >= 200){
                loadedCount++;
                getShareImages.results.push(img);
                return img.src;
            } 
        };
        if(loadedCount == getShareImages.results.length){
            return getShareImages.defaultimg;
        }
    }
}
getShareImages.init();

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。