Skip to content

Commit 96cacaf

Browse files
committed
Clear all notifications button
1 parent cfc658f commit 96cacaf

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

popup.css

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,69 @@ body {
33
padding: 0;
44
}
55

6+
#popup {
7+
margin-top: 10px;
8+
}
9+
610
h1, h2, h3, h4, h5, h6 {
711
font-family: inherit;
812
font-weight: 500;
913
line-height: 1.2;
1014
color: inherit;
1115
}
1216

13-
button {
14-
display: none;
17+
.btn {
18+
display: inline-block;
19+
margin-bottom: 0;
20+
font-weight: normal;
21+
text-align: center;
22+
vertical-align: middle;
23+
cursor: pointer;
24+
background-image: none;
25+
border: 1px solid transparent;
26+
white-space: nowrap;
27+
padding: 6px 12px;
28+
font-size: 14px;
29+
line-height: 1.42857;
30+
border-radius: 4px;
31+
-webkit-user-select: none;
32+
-moz-user-select: none;
33+
-ms-user-select: none;
34+
user-select: none;
35+
padding: 1px 5px;
36+
font-size: 12px;
37+
line-height: 1.5;
38+
border-radius: 3px;
39+
}
40+
41+
.btn-default {
42+
color: #333;
43+
background-color: #fff;
44+
border-color: #ccc;
45+
}
46+
47+
.btn-default:hover,
48+
.btn-default:focus,
49+
.btn-default:active,
50+
.btn-default.active,
51+
.open > .btn-default.dropdown-toggle {
52+
color: #333;
53+
background-color: #e6e6e6;
54+
border-color: #adadad;
55+
}
56+
57+
.btn:hover, .btn:focus {
58+
color: #333;
59+
text-decoration: none;
60+
}
61+
62+
.btn.disabled, .btn[disabled] {
63+
cursor: not-allowed;
64+
pointer-events: none;
65+
opacity: .65;
66+
filter: alpha(opacity=65);
67+
-webkit-box-shadow: none;
68+
box-shadow: none;
1569
}
1670

1771
a {

popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<link rel="stylesheet" href="popup.css">
55
</head>
66
<body>
7-
<div id="popup" class="notify-stream"></div>
7+
<div id="popup" class="notify-stream">载入中...</div>
88
<script src="jquery.js"></script>
99
<script src="popup.js"></script>
1010
</body>

popup.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,36 @@ bg.getNotifications(function(data) {
66
alert('未登录');
77
chrome.tabs.create({ url: 'https://segmentfault.com/user/login' });
88
}
9-
$('#popup').append($html.find('.stream-list').html());
9+
$('#popup').empty().append($html.find('.stream-list').html());
1010
});
1111

1212
$('#popup').on('click', 'a', function() {
1313
var $this = $(this);
1414
var href = $this.attr('href');
15-
if (href.substring(0, 1) === '/' && href.substring(0, 2) !== '//') {
16-
href = 'https://segmentfault.com' + href;
17-
}
15+
href = transUrl(href);
1816
chrome.tabs.create({ url: href });
1917
return false;
2018
});
19+
20+
$('#popup').on('click', 'button', function() {
21+
var $this = $(this);
22+
var $unViewed = $('#popup').find('.stream-list__item:not(".viewed")');
23+
$unViewed.each(function(index, el) {
24+
var $el = $(el);
25+
$el.addClass('viewed');
26+
var url = $el.find('a:last').attr('href');
27+
url = transUrl(url);
28+
$.ajax({
29+
url: url,
30+
method: 'get'
31+
});
32+
});
33+
$this.attr('disabled', true);
34+
});
35+
36+
function transUrl(url) {
37+
if (url.substring(0, 1) === '/' && url.substring(0, 2) !== '//') {
38+
url = 'https://segmentfault.com' + url;
39+
}
40+
return url;
41+
}

0 commit comments

Comments
 (0)