-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
64 lines (58 loc) · 2.39 KB
/
popup.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
/*
Copyright (C) David Bern
See COPYRIGHT.txt for details
*/
var background = chrome.extension.getBackgroundPage();
addEventListener("unload", function (event) {
background.unloadEvent();
}, true);
// Set the watchlist url to the computed one, based on https and lang settings
$(document).ready(function(){
$('#watchlist').prop('href', watchlistLink);
})
//localStorage.removeItem('unread');localStorage.removeItem('last_date');
checkNewItems(displayUnread);
function displayUnread(data) {
var rss = parseRSS(data);
// Delegate adds mousedown handlers to new items as they appear
$("html > body").delegate(".item", "mousedown", function(){
var m = $(this).removeClass('unread').attr('ms');
console.log("Removing item: " + m);
var reg = new RegExp(';'+m+'$|'+m+';?');
localStorage['unread'] = localStorage['unread'].replace(reg, '');
updateBadge();
}).delegate(".item", "mouseenter", function() {
$('#status').text(unescape(this.getAttribute('desc')));
}).delegate(".item", "mouseleave", function() {
$('#status').text('');
});
var lastDate = null;
var string = new Array();
rss.each(function(){
var i = this;
var msDate = Date.parse(i.pubDate);
var d = new Date(msDate);
var strTime = d.toLocaleTimeString().replace(/:\d+$/, '')
var date = d.toDateString();;
if (lastDate != date) {
if (lastDate != null) string.push('<hr/>');
string.push('<div class="date">'+date+'</div>');
lastDate = date;
}
var unread = '';
if (localStorage['unread'].indexOf(msDate) != -1)
unread = ' unread';
string.push('<span desc="'+escape(i.description)+'" ms="'+msDate+'" class="item'+unread+'">(<a class="diff" href="'+i.link+'?diff=cur&oldid=prev" target="_blank"> d </a>) ');
string.push(strTime+' <a href="'+i.link+'" class="link" target="_blank">'+i.title+'</a> '+i['dc:creator']+'</span><br/>');
});
$(document.body).append(string.join(''));
if (localStorage['autoRead'] != 'true') {
// Show mark all read button
$('<a href="#" id="markall">Mark All Read</a>').click(function(){
$("span.item").removeClass('unread');
localStorage['unread'] = "";
updateBadge();
}).appendTo('body');
}
$('<div id="status"></div>').appendTo('body');
}