Skip to content

Commit 602194a

Browse files
committed
Add "checkDiffs", "showDiff", message from Popup to background.
1 parent 6f509c6 commit 602194a

File tree

5 files changed

+113
-14
lines changed

5 files changed

+113
-14
lines changed

background.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ chrome.extension.onMessage.addListener(function(msg, _, sendResponse) {
1212
chrome.storage.sync.get(null, function (items) {
1313
sendResponse(items);
1414
});
15+
} else if (msg.checkDiffs) {
16+
console.log("checkDiffs not implement");
17+
sendResponse('Not implement');
18+
} else if (msg.removeDiff) {
19+
console.log("msg.removeDiff");
20+
chrome.storage.sync.remove(msg.url, function () {
21+
sendResponse("Item removed");
22+
});
23+
} else if (msg.showDiff) {
24+
console.log("showDiff not implement");
25+
sendResponse('showDiff Not implement');
1526
}
1627

1728
return true;
@@ -30,7 +41,7 @@ function addPage(msg, sendResponse) {
3041
console.log(xhr.responseText);
3142
console.log("XML: ", xhr.responseXML);
3243

33-
resultMsg = "Page saved " + (getPrev(url) ? "<b>again...</b>" : "!");
44+
resultMsg = "Page saved " + (getPrev(url) ? "again..." : "!");
3445

3546
store(url, xhr.responseText);
3647

@@ -50,14 +61,15 @@ function addPage(msg, sendResponse) {
5061
var lengthByte = 100;
5162
var hash = "ABCDEFG";
5263
var checkIntervalSecond = 600;
53-
var item = {
54-
url: {
64+
var changed = false;
65+
var item= {};
66+
item[url] = {
5567
title: msg.title,
5668
dateAdd: Date.now(),
5769
lengthByte: lengthByte,
5870
hash: hash,
59-
checkIntervalSecond: checkIntervalSecond
60-
}
71+
checkIntervalSecond: checkIntervalSecond,
72+
changed: changed
6173
};
6274
chrome.storage.sync.set(item);
6375

js/list.js

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,81 @@
1-
/*global chrome:true */
1+
/*global chrome,webkitNotifications:true */
22

33
$(function () {
44
// Get all urls store in storage.sync
55
// item { key: value}
66
// { "http://twitter.github.com/bootstrap/index.html":
77
// {title:"Twitter Bootstrap", dateAdd:1350049430341, length:10, hash:"EEEEEEEE", checkInterval:10}
88
// }
9+
10+
function removeListItem(url) {
11+
chrome.extension.sendMesssage({removeDiff:true, url: url}, function(response) {
12+
if (response) {
13+
var notification = webkitNotifications.createNotification(
14+
'icon.png', // icon url - can be relative
15+
'WebPageDiff', // notification title
16+
response // notification body text
17+
);
18+
notification.show();
19+
}
20+
document.location.reload(true);
21+
});
22+
}
23+
924
chrome.extension.sendMessage({getList: true}, function(list) {
10-
var markup = '<div class="well well-large"><ul>';
25+
var markup = '';
26+
markup = '<div class="span10 offset1">';
27+
markup += '<table class="table table-condensed table-striped table-hover">';
1128
for (var item in list) {
12-
markup += '<li>';
13-
markup += '<a href="' + list[item] + '">' + list[item].title + '</a>';
14-
markup += '</li>';
29+
markup += '<tr>';
30+
markup += '<td>';
31+
if (list[item].changed) {
32+
markup += '<i class="icon-star"></i>';
33+
} else {
34+
markup += '<i class="icon-minus"></i>';
35+
}
36+
markup += ' <a class="clickListItem" href="' + item + '">' + list[item].title + '</a></td>';
37+
markup += '<td><a class="btn removeListItem" href="' + item + '"><i class="icon-remove-sign"></i> Remove</a></td>';
38+
markup += '</tr>';
1539
}
16-
markup += '</ul></div>';
40+
markup += '</table>';
41+
markup += '</div>';
1742
$('#listContent').html(markup);
1843
});
44+
45+
$('body').on('click', function(evt) {
46+
//evt.preventDefault();
47+
//evt.stopPropagation();
48+
if ($(evt.currentTarget).hasClass('clickListItem')) {
49+
evt.preventDefault();
50+
evt.stopPropagation();
51+
console.log('a.clickListItem');
52+
//chrome.tabs.create({url: $(evt.document.location.reload(true)currentTarget).attr("href")});
53+
}
54+
});
55+
56+
$('body').on('click', function(evt) {
57+
//evt.preventDefault();
58+
//evt.stopPropagation();
59+
console.log("removeListItem");
60+
if ($(evt.currentTarget).hasClass('removeListItem')) {
61+
evt.preventDefault();
62+
evt.stopPropagation();
63+
//removeListItem($(evt.currentTarget).attr("href"));
64+
var url = $(evt.currentTarget).attr("href");
65+
chrome.extension.sendMesssage({removeDiff:true, url: url}, function(response) {
66+
/*
67+
if (response) {
68+
var notification = webkitNotifications.createNotification(
69+
'icon.png', // icon url - can be relative
70+
'WebPageDiff', // notification title
71+
response // notification body text
72+
);
73+
notification.show();
74+
}
75+
document.location.reload(true);
76+
*/
77+
});
78+
}
79+
});
1980
});
2081

js/popup.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,24 @@ $(function ($) {
3232
window.close();
3333
*/
3434
});
35+
$('#checkDiffs').on('click', function (evt) {
36+
var msg = { checkDiffs: true };
37+
chrome.extension.sendMessage(msg, function(response) {
38+
window.close();
39+
});
40+
});
41+
$('#showDiff').on('click', function (evt) {
42+
var msg = { showDiff: true };
43+
chrome.extension.sendMessage(msg, function(response) {
44+
if (response) {
45+
var notification = webkitNotifications.createNotification(
46+
'icon.png', // icon url - can be relative
47+
'WebPageDiff', // notification title
48+
response // notification body text
49+
);
50+
notification.show();
51+
}
52+
window.close();
53+
});
54+
});
3555
})(jQuery);

list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<body>
1212
<div class="container">
1313
<div class="row">
14-
<h2>WebPageDiff - List Manager</h2>
14+
<div class="well"><h2>WebPageDiff - List Manager</h2></div>
1515
</div>
16-
<div id="listContent">
16+
<div class="row" id="listContent">
1717
</div>
1818
</div>
1919
</body>

popup.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ <h4>WebPageDiff</h4>
2727
<div class="clickable" id="addPage"><i class="icon-plus-sign"></i> Add Page</div>
2828
</li>
2929
<li>
30-
<div class="clickable" id="manageList"><i class=" icon-list"></i> Manage List</div>
30+
<div class="clickable" id="showDiff"><i class="icon-eye-open"></i> Show Diff</div>
31+
</li>
32+
<li>
33+
<div class="clickable" id="checkDiffs"><i class="icon-refresh"></i> Check Diffs</div>
34+
</li>
35+
<li>
36+
<div class="clickable" id="manageList"><i class="icon-list"></i> Manage List</div>
3137
</li>
3238
</ul>
3339
</body>

0 commit comments

Comments
 (0)