/
clear-feeds.js
109 lines (109 loc) · 4.4 KB
/
clear-feeds.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(function () {
var regExp = /https?:\/\/weibo\.com/;
if (!regExp.test(location.href)) {
return;
}
if (!Number($CONFIG.islogin)) {
alert("请先登录微博!");
return;
}
try {
if(!confirm('确定清空微博!!!')) return;
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "//lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js";
s.onload = function () {
var scriptContainerId = "W_clear-feeds__" + new Date().getTime();
var timer;
var profileUrl =
"//weibo.com/" +
parent.$CONFIG.uid +
"/profile?profile_ftype=1&is_all=1&ajaxpagelet=1&ajaxpagelet_v6=1";
var feedsUrl =
"//weibo.com/" +
parent.$CONFIG.uid +
"/profile?pids=Pl_Official_MyProfileFeed__20&profile_ftype=1&is_all=1&ajaxpagelet=1&ajaxpagelet_v6=1";
function appendScriptContainer() {
document.body.appendChild($("<div id=" + scriptContainerId + "></div>")[0]);
}
function deleteItem(mid) {
// 档案娘助手 chrome 插件
// https://chrome.google.com/webstore/detail/%E6%A1%A3%E6%A1%88%E5%A8%98%E5%8A%A9%E6%89%8B/abfopppplogcojgdcfhhffngkabbhifm
// url: "https//api.weibo.com/2/statuses/user_timeline.json?source=209678993&count=20&trim_user=1&uid=" + $CONFIG.uid + "&page=" + page,
return $.ajax({
url: "//weibo.com/aj/mblog/del?ajwvr=6",
type: "POST",
dataType: "json",
data: { mid: mid }
})
.done(function (ret) {
if (ret.code === '100000') {
var $feed = $("[mid=" + mid + "]");
if($feed.length) {
$feed.hide('slow', function() {
$feed.remove()
})
}
var count = $($(".tb_counter .W_f18")[2]).text();
count--;
$($(".tb_counter .W_f18")[2]).text(count);
}
})
}
function getFeedNodes() {
return $("[action-type=feed_list_item]");
}
function loadMore(url, cb) {
// 点击全部按钮
$.get(url)
.done(function (html) {
if (!$("div#" + scriptContainerId).length) {
appendScriptContainer();
}
$("#" + scriptContainerId).html(html);
timer = setTimeout(function () {
clearTimeout(timer);
cb();
}, 2000);
})
.fail(function (e) {
console.log(e);
alert("清空失败!请刷新页面后重试!");
});
}
function deleteFeeds() {
var $feedNodes = getFeedNodes();
var nodeLength = $feedNodes.length;
var jobCounter = 0;
var index = 0;
var dtimer
if (nodeLength === 0) {
return alert("清空微博成功!");
}
function loopDelete() {
dtimer = setTimeout(function() {
clearTimeout(dtimer)
const $feed = $feedNodes[index];
var mid = $($feed).attr("mid");
deleteItem(mid).always(function () {
jobCounter++;
// all ajax done
jobCounter === nodeLength && loadMore(feedsUrl, deleteFeeds);
});
index++;
index < nodeLength ? loopDelete() : null;
}, 1000)
}
loopDelete()
}
appendScriptContainer();
loadMore(profileUrl, deleteFeeds);
};
s.onerror = function (e) {
alert(e);
};
document.getElementsByTagName("head")[0].appendChild(s);
} catch (e) {
alert(e);
}
})();