Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Zhuochun
// 2013-12-15
function eventFire(el, etype) {
if (el.fireEvent) {
(el.fireEvent('on' + etype));
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
// handle select delete tweets
var to_delete = [];
tweets = Array.prototype.slice.call(document.getElementsByClassName('WB_feed_type'), 0);
tweets.forEach(function (t) {
t.style.border = '1px solid red';
t.onclick = function (e) {
if (e.currentTarget.style.border == '1px solid blue') {
to_delete = to_delete.filter(function(i) { return i != e.currentTarget; });
e.currentTarget.style.border = '1px solid red';
} else {
e.currentTarget.style.border = '1px solid blue';
to_delete.push(e.currentTarget);
}
};
});
// add delete button
var btn = document.createElement('button');
btn.appendChild(document.createTextNode('Delete!'));
document.body.appendChild(btn);
btn.onclick = function () {
to_delete.forEach(deleteTweet);
// confirm delete
Array.prototype.forEach.call(document.getElementsByClassName('W_layer'), confirmDelete);
};
// delete a tweet
function deleteTweet(t) {
var delete_btn = t.querySelector('[title="删除此条微博"]');
eventFire(delete_btn, 'click');
}
// confirm delete
function confirmDelete(t) {
if (t.style.display != 'none') {
eventFire(t.querySelector('a.W_btn_d[action-type="ok"]'), 'click');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.