-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
88 lines (84 loc) · 2.2 KB
/
background.js
File metadata and controls
88 lines (84 loc) · 2.2 KB
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
var ids=[];
var messages=[];
var latestId;
$(function () {
engine();
setInterval(engine,20000);
});
function engine()
{
var newTweets=[];
$.get('https://twitter.com/i/notifications',function(data){
var htmlData=data;
$data=$(htmlData).find("#stream-items-id").eq(0);
$data.find('.activity-supplement').remove(); //remove unnecessary data from required
$data.find('.activity-truncated-tweet').remove();
//$('body').append($data);
for(i=0;i<$data.find('li.stream-item').length;i++)//looping through notifications
{
ids[i]=$data.find('li.stream-item').eq(i).attr('data-item-id');//grabbing id
messages[i]=($($data).find('li.stream-item').eq(i).find('div.stream-item-activity-line').text()).replace(/\n/g,'').trim();
//grabbing message
}
/*latestId=ids[0];
console.log(ids);
console.log(messages);*/
if(latestId==ids[0]){
//no update
}
else if (latestId===undefined){
var firstRun={
type:"basic",
title:"Twitter Notifier",
message:"Check your twitter account for latest notifications",
contextMessage:"Twitter Notifier",
buttons:[{
title:"Open Link"
}],
iconUrl:"icon.png"
};//details that chrome require from you
chrome.notifications.onButtonClicked.addListener(function(){
window.open('https://twitter.com/i/notifications');
});
chrome.notifications.create(firstRun);
latestId=ids[0];
}
else if(latestId!=ids[0]){//there is some new activity in user account
for(j=0;j<ids.length;j++){//finding all notifications in 20 secs.
if(latestId==ids[j]){
break;
}
else{
if(messages[j]!=""){
newTweets[j]=messages[j];
}
}
}
latestId=ids[0];
}
if(newTweets.length==0){
//nothing
}
else{
for(i=0;i<newTweets.length;i++){
var myTweet={
type:"basic",
title:"You got new notification in twitter",
message:newTweets[i],
contextMessage:"Twitter Notifier",
buttons:[{
title:"Open Link"
}],
iconUrl:"icon.png"
};
chrome.notifications.onButtonClicked.addListener(function(){
window.open('https://twitter.com/i/notifications');
});
chrome.notifications.create(myTweet);
}
}
// console.log(latestId);
// console.log(newTweets);
});
//alert();
}