知乎专栏粉丝抽奖脚本

var fan_num = 5065;
var offset = Math.round(Math.random() * fan_num);
var url = "https://www.zhihu.com/api/v4/columns/c_101903169/followers?include=data%5B%2A%5D.follower_count%2Cgender%2Cis_followed%2Cis_following&limit=10&offset="+offset;
console.log(url);
var resp = fetch(url)
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    var len = myJson['data'].length;
    var choices = Math.round(Math.random() * len);
    
    console.log( myJson['data'][choices]['url'] );
    console.log( myJson['data'][choices]['name'] );
    alert("中奖者是: " + myJson['data'][choices]['name'] );
    window.open( myJson['data'][choices]['url'] );
  });
  

Pingbacks已关闭。

评论已关闭