Last active
September 6, 2015 05:35
-
-
Save naoyeye/5f5067790bc08c0c83e7 to your computer and use it in GitHub Desktop.
批量取消关注豆瓣小站
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function() { | |
Array.prototype.del = function (n){ | |
if (n < 0) { | |
return this; | |
} else { | |
return this.slice(0,n).concat(this.slice(n+1,this.length)); | |
} | |
} | |
var num = parseInt($('#content h1').text().split(/\(|\)/)[1]); | |
var total = parseInt(num / 20); | |
var idList = new Array(); | |
var timer = 0; | |
var s = 0; | |
function unfollow() { | |
$.ajax({ | |
type: 'POST', | |
url : 'http://www.douban.com/j/contact/removecontact', | |
data: {people: idList[0], ck: 'Qrdj'}, | |
success: function(resp) { | |
if (resp.result) { | |
s++; | |
console.log('成功取关', idList[0], s); | |
if (s === num) { | |
console.log('已经全部取消关注'); | |
alert('已经全部取消关注'); | |
return; | |
} | |
idList = idList.del(0); | |
setTimeout(function () { | |
unfollow(); | |
}, 1300); | |
} | |
} | |
}); | |
} | |
for (i = 0; i <= total; i++) { | |
getIdList(); | |
function getIdList() { | |
$.get('http://www.douban.com/people/post-rocker/contact_site?start=' + (20 * i), function (data) { | |
$('.user-list li', data).each(function (i, e) { | |
// console.log(e); | |
idList.push($(e).attr('id').split('u')[1]); | |
if (idList.length === num) { | |
console.log('读取结束。准备发请求'); | |
unfollow(); | |
} | |
}); | |
}) | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment