-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
78 lines (69 loc) · 2.89 KB
/
background.js
File metadata and controls
78 lines (69 loc) · 2.89 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
$(document).ready(function() {
var notificationNumber=1;
function getFeed(){
chrome.browserAction.getBadgeText({}, function(result) {
if(result==="0")notificationNumber=1;
});
storageOfCurrentFeed = new Array();
chrome.browserAction.setBadgeBackgroundColor({color: "#CF0016"});
//https://www.mev.hr/index.php/category/racunarstvo-rss/racunarstvo/feed/
//http://lorem-rss.herokuapp.com/feed?unit=minute
//feed to parse
var url = 'https://www.mev.hr/index.php/category/racunarstvo-rss/racunarstvo/feed/';
chrome.storage.local.get("odabraniSmjer", function(items) {
switch(items.naziv){
case "racunarstvo":
url = 'https://www.mev.hr/index.php/category/racunarstvo-rss/racunarstvo/feed/';
break;
case "menadzment":
url = 'https://www.mev.hr/index.php/category/menadzment-rss/menadzment-turizma-i-sporta/feed/';
break;
case "odrziviRazvoj":
url = 'https://www.mev.hr/index.php/category/odrzivi-razvoj-rss/odrzivi-razvoj/feed/';
break;
case 'svi':
url = 'https://www.mev.hr/index.php/feed/';
break;
default :
url = 'https://www.mev.hr/index.php/feed/';
break;
}
feednami.load(url)
.then(feed => {
console.log(feed);
for(let entry of feed.entries){
storageOfCurrentFeed.push(entry.guid);
}
//dohvacanje lokalnog spremista
chrome.storage.local.get("value", function(items) {
//console.log(items);
//provjera ako je obavijest nova
if(feed.entries[0].guid!==items.value[0]){
chrome.browserAction.setBadgeText({ text: String(notificationNumber)});
var url=feed.entries[0].link;
var opt = {
type: "basic",
title: feed.entries[0].title,
message: feed.entries[0].link,
iconUrl: "icon.png"};
chrome.notifications.create(url,opt,function(notificationId){});
notificationNumber+=1;
}
});
//spremanje obavijesti u lokalnu memoriju browsera
chrome.storage.local.set({'value': storageOfCurrentFeed}, function() {
// Notify that we saved.
console.log('Settings saved');
});
});
});
}
chrome.notifications.onClicked.addListener(function(notificationId) {
chrome.tabs.create({url: notificationId});
chrome.notification.clear(id, clearCallback);
notificationNumber--;
});
//provjera svakih 10 sekundi ako postoji nova obavijest
setInterval(getFeed,10000);
getFeed();
});