-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
96 lines (85 loc) · 3.14 KB
/
background.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
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
89
90
91
92
93
94
95
96
var messages=[];
var ids=[];
var latestid;
$(function(){
engine();
setInterval(engine,2000);
});
function engine(){
var newtweets=[];
$.get('https://twitter.com/i/notifications',function(data){ //getting data from "https://twitter.com/i/notifications"
var htmldata=data;
$data= $(htmldata).find('#stream-items-id').eq(0);
$data.find('.ActivityItem-quoteTweetContainer').remove();
$data.find('.QuoteTweet').remove();
$data.find('.ActivityItem-facepileContainer').remove();
//$data.find('.activity-timestamp').remove(); //filtering the unwanted data
$data.find('.ActivityItem-dismissMenu').remove();
$data.find('.ActivityItem-icon').remove();
//$data.find('.QuoteTweet').remove();
$data.find('.ActivityItem-activityTimestamp').remove();
$('body').append($data); // appending the data to th html body
for(i=0;i<$data.find('li.stream-item').length;i++) // filtering every li item.
{
ids[i]=$data.find('li.stream-item').eq(i).attr('data-item-id');
messages[i]= ($($data).find('li.stream-item').eq(i).find('div.ActivityItem-displayText').text()).replace(/\n/g,' ').trim();
}
//console.log(messages);
if(latestid==ids[0]){
//do noting;
}
else if(latestid === undefined)
{
var first={
type: "basic",
title:"rich_notifier",
message:"you may have some other notifications please check your twitter account ",
iconUrl :"git.png",
};
chrome.notifications.create(first); //google api for notifying the first popup
latestid=ids[0];
}
else if(latestid != ids[0] )
{
for(j=0;j<ids.length;j++)
{
if(latestid==ids[j])
{
break;
}
else
{
if(messages[j]!=""){
newtweets[j]=messages[j];
}
}
}
latestid=ids[0];
}
if(newtweets.length == 0)
{
//do nothing
}
else{
for(i=0;i<newtweets.length;i++)
{
var tweet={
type: "basic",
title:"New notifications",
message: newtweets[i],
contextMessage:"Rich Notifier",
buttons:[{
title:"open link" //link in the notification panel
}],
iconUrl :"icon.png",
};
chrome.notifications.onButtonClicked.addListener(function(){ // google api for notifying the notifications
window.open('https://twitter.com/i/notifications'); //function to open the link on clicking the button
});
chrome.notifications.create(tweet);
}
}
console.log(newtweets); // shows new tweets on the console
console.log(latestid);
});
}