forked from feross/Facebook-Like-Everything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
46 lines (39 loc) · 1.66 KB
/
script.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
/*
I Like Everything
Description: Like everything on Facebook with this JavaScript Bookmarklet
Author: Feross Aboukhadijeh
Read more: http://feross.org/like-everything-on-facebook/
*/
var sad = document.getElementsByTagName('*'),
happy = [],
halt = false;
// Select only the Like buttons.
// Convert the sad NodeList to a happy Array.
for (var i = 0; i < sad.length; i++) {
if (sad[i] && (sad[i].title == 'Like this' || sad[i].title == 'Like this comment')) {
happy.push(sad[i]);
}
}
var happyDiv = document.createElement('div');
happyDiv.innerHTML = '<div id=\'happy\' style=\'background-color:#ddd;font-size:16px;text-align:center;position:fixed;top:40px;right:40px;width:200px;height:100px;border:4px solid black;z-index:9999;padding-top:15px;\'><span>0</span> of '+happy.length+' items liked.<div id=\'happyStatus\' style=\'margin-top:30px;\'><a id=\'happyButton\' href=\'#\' style=\'display:block;\' onclick=\'haltFn();\'>Stop it.</a></div></div>';
document.getElementsByTagName('body')[0].appendChild(happyDiv);
function happyFn(happy) {
if (halt || !happy || !happy.length) {
document.getElementById('happyStatus').innerHTML = 'Done!';
return;
}
happy[0].click();
happy[0].style.color='#FF0000';
var countSpan = document.querySelector('#happy span');
countSpan.innerHTML = parseInt(countSpan.innerHTML) + 1;
// Wait for each Like to be processed before trying the next.
// Facebook enforces this requirement.
window.setTimeout(function() {
happyFn(happy.splice(1));
}, 5000);
}
function haltFn() {
halt = true;
return false; // prevent default event
}
happyFn(happy);