V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
artandlol
V2EX  ›  分享创造

新年 V2 头像拼图

  •  
  •   artandlol · 2017-01-01 02:46:17 +08:00 · 7244 次点击
    这是一个创建于 2680 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第 1 条附言  ·  2017-01-01 14:12:50 +08:00

    献上javascript抓取头像代码,非程序员 轻点

    javascript: 
    var htmlURL = window.location.href;
    var baselink = htmlURL.match(/.*=/g);
    var toplink = "https://www.v2ex.com/recent?p=";
    var toplinkNaN  = "https://www.v2ex.com/recent?p=NaN";
    if ( baselink != toplink || htmlURL==toplinkNaN )
    {
    window.open("https://www.v2ex.com/recent?p=1");
    localStorage.setItem("message",'');
    }
    function getLastNumberStr(str)
    {
     var strs = str.replace(/.*=/g,'');
     return strs;
    }
    var i = getLastNumberStr(htmlURL);
    i++;
    self.location=toplink+i.toString();
    var singlereg= /(\/\/cdn\.v2ex\.co\/avatar).*(png)/g;
    var html = document.documentElement.innerHTML;
    var htmlele = html.match(singlereg).toString().replace(/normal/g,"large").replace(/\,/g," ").replace(/\/\//g,"https://").replace(/png/g,"png\n");
    var localdata=localStorage.getItem("message");
    htmlele += localdata;
    localStorage.setItem("message",htmlele);
    console.log(htmlele);
    
    第 2 条附言  ·  2017-01-07 14:54:23 +08:00

    代码更新 最后面的数值是v2总页面数。本人非程序员,轻拍。:)

    Array.prototype.uniquestr = function() {
    	var res = [];
    	var json = {};
    	for (var i = 0; i < this.length; i++) {
    		if (!json[this[i]]) {
    			res.push(this[i]);
    			json[this[i]] = 1;
    		}
    	}
    	return res;
    }
    var Urls = function(startUrl) {
    		this.startUrl = startUrl;
    		this.page = 0;
    		this.homePage = '';
    		this.heartsRecv = '';
    	}
    Urls.prototype.crawl = function(titles) {
    	var self = this;
    	var url = self.startUrl + titles;
    	titles--;
    	var singlereg = /(\/\/cdn\.v2ex\.co\/avatar).*(png)/g;
    	$.get(url, function(data, status) {
    		self.homePage = data;
    		if (titles != undefined) {
    			self.heartsRecv += data;
    		}
    		setTimeout(function() {
    			if (titles > 0) {
    				self.crawl(titles);
    			} else {
    				self.heartsRecv = self.heartsRecv.match(singlereg).uniquestr().toString().replace(/normal/g, "large").replace(/\,/g, " ").replace(/\/\//g, "https://").replace(/png/g, "png\n");
    				console.log(self.heartsRecv);
    				return false;
    			}
    		}, 1000);
    	});
    }
    new Urls('https://www.v2ex.com/recent?p=').crawl(10000);
    
    102 条回复    2017-01-04 09:22:01 +08:00
    1  2  
    itfanr
        101
    itfanr  
       2017-01-03 13:40:30 +08:00
    @artandlol 额 好复杂
    KanVivii
        102
    KanVivii  
       2017-01-04 09:22:01 +08:00 via iPhone
    没有自己 伤心
    1  2  
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2432 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:01 · PVG 17:01 · LAX 02:01 · JFK 05:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.