-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentscript.js
42 lines (42 loc) · 1.66 KB
/
contentscript.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
//getting access
var successURL = 'https://www.facebook.com/connect/login_success.html';
function onFacebookLogin() {
if (!localStorage.accessToken) {
chrome.tabs.getAllInWindow(null, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].url.indexOf(successURL) == 0) {
var params = tabs[i].url.split('#')[1];
access = params.split('&')[0]
console.log(access);
localStorage.accessToken = access;
chrome.tabs.onUpdated.removeListener(onFacebookLogin);
return;
}
}
});
}
}
chrome.tabs.onUpdated.addListener(onFacebookLogin);
// scraping chat data...
var max = 0;
while(true){
var onlineFriends = document.getElementsbyClassName("_55lr");
//we need to check if the friend is actually online. if the element "_568" is blank, they are online
var friendStatus = document.getElementsbyClassName("_568-");
var numOnline = friendStatus.length;
for(i = 0; i < friendStatus.length; i++){
if(friendStatus[i] !== ""){ //if not empty
numOnline--;
}
}
//comparing to the max: not quite sure how to do this properly for a script running over a period of time
if(numOnline > max){
max = numOnline
var x = new Date();
hourToPost = x.getHours();
minToPost = x.getMinutes();
document.clear();
document.write("<h1> Best time: </h1>");
document.write("<p>"+hourToPost+":"+minToPost+"</p>");
}
} //maybe set a timeout