Created
December 15, 2013 16:41
-
-
Save zhuochun/7975113 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
// 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