Skip to content

Commit cfc658f

Browse files
committed
Initial Commit
0 parents  commit cfc658f

12 files changed

+263
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Kokororin (https://kotori.love)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the "Software"),
7+
to deal in the Software without restriction, including without limitation
8+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
and/or sell copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included
13+
in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
IN THE SOFTWARE.

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SegmentFault Notifier
2+
3+
Chrome Notifier Extension for https://segmentfault.com
4+
5+
6+
## Install
7+
https://chrome.google.com/webstore/detail/hliakgdmocbgojcikbeloeifaoiclkhg
8+
9+
## Screenshots
10+
![](https://cdn.rawgit.com/kokororin/segmentfault-notifier/master/screenshot.png)

background.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var getNotifications = function(cb) {
2+
$.ajax({
3+
url: 'https://segmentfault.com/user/notifications',
4+
method: 'get',
5+
dataType: 'html'
6+
}).then(function(data) {
7+
typeof cb === 'function' && cb(data);
8+
var $list = $(data).find('.notify-stream');
9+
if ($list.length === 0) {
10+
chrome.browserAction.setBadgeText({
11+
text: '!'
12+
});
13+
return;
14+
}
15+
16+
var $unViewed = $list.find('.stream-list__item:not(".viewed")');
17+
chrome.browserAction.setBadgeText({
18+
text: $unViewed.length + ''
19+
});
20+
});
21+
};
22+
23+
setInterval(getNotifications, 1500);

jquery.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

logo-128.png

9.94 KB
Loading

logo-16.png

543 Bytes
Loading

logo-48.png

2.12 KB
Loading

manifest.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "SegmentFault Notifier",
3+
"description": "SegmentFault消息提醒",
4+
"icons": {
5+
"128": "logo-128.png",
6+
"16": "logo-16.png",
7+
"48": "logo-48.png"
8+
},
9+
"browser_action": {
10+
"default_icon": "logo-48.png",
11+
"default_popup": "popup.html"
12+
},
13+
"background": {
14+
"scripts": ["jquery.js", "background.js"]
15+
},
16+
"manifest_version": 2,
17+
"permissions": [
18+
"https://segmentfault.com/*"
19+
],
20+
"version": "1.1.0"
21+
}

popup.css

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
h1, h2, h3, h4, h5, h6 {
7+
font-family: inherit;
8+
font-weight: 500;
9+
line-height: 1.2;
10+
color: inherit;
11+
}
12+
13+
button {
14+
display: none;
15+
}
16+
17+
a {
18+
color: #009a61;
19+
text-decoration: none;
20+
}
21+
22+
a:hover, a:focus {
23+
color: #004e31;
24+
text-decoration: underline;
25+
}
26+
27+
.stream-list {
28+
margin-bottom: 10px;
29+
}
30+
31+
.stream-list.top-indent {
32+
margin-top: -10px;
33+
}
34+
35+
.stream-list__item {
36+
margin: 0;
37+
border-bottom: 1px solid #eee;
38+
padding: 10px 0;
39+
}
40+
41+
.stream-list__item .author {
42+
margin-bottom: 10px;
43+
color: #999;
44+
font-size: 13px;
45+
}
46+
47+
.stream-list__item .author a {
48+
color: #999;
49+
}
50+
51+
.stream-list__item .author small {
52+
color: #ddd;
53+
}
54+
55+
.stream-list__item .title {
56+
display: inline;
57+
margin: 0 5px 0 0;
58+
font-size: 16px;
59+
}
60+
61+
.stream-list__item .title a {
62+
color: #333;
63+
}
64+
65+
.stream-list__item .title a:hover {
66+
color: #017e66;
67+
}
68+
.stream-list__item .title a:visited {
69+
font-weight: 400;
70+
}
71+
72+
.stream-list__item .small-title {
73+
margin: 0 0 5px;
74+
font-size: 16px;
75+
}
76+
77+
.stream-list__item .split:before {
78+
content: "·";
79+
color: #ddd;
80+
}
81+
82+
.stream-list__item .summary {
83+
overflow: auto;
84+
overflow-x: hidden;
85+
}
86+
87+
.stream-list__item .excerpt {
88+
margin: 5px 0 0;
89+
color: #777;
90+
font-size: 13px;
91+
line-height: 1.6;
92+
overflow: hidden;
93+
}
94+
95+
.blog-stream .stream-list__item {
96+
padding: 15px 0;
97+
}
98+
99+
.blog-stream .stream-list__item .author {
100+
margin-top: 10px;
101+
}
102+
103+
.blog-stream .stream-list__item .author a {
104+
color: #009a61;
105+
}
106+
107+
.blog-stream .stream-list__item .blog-title {
108+
font-size: 16px;
109+
margin-top: 0;
110+
margin-bottom: 10px;
111+
}
112+
113+
.blog-stream .stream-list__item .article-list {
114+
border-left: 5px solid #EEE;
115+
padding: 10px 20px;
116+
margin-top: 10px;
117+
margin-bottom: 0;
118+
}
119+
120+
.stream-list__item.highlight {
121+
background: #FFF9EB;
122+
}
123+
124+
.notify-stream .time {
125+
margin: 15px 0 0;
126+
padding: 5px 0;
127+
border-bottom: 1px solid #eee;
128+
font-size: 14px;
129+
}
130+
131+
.notify-stream .stream-list__item:before {
132+
margin-left: 10px;
133+
content: "";
134+
display: inline-block;
135+
width: 8px;
136+
height: 8px;
137+
background: #F5A623;
138+
-moz-border-radius: 100%;
139+
-webkit-border-radius: 100%;
140+
border-radius: 100%;
141+
}
142+
143+
.notify-stream .stream-list__item.viewed:before {
144+
visibility: hidden;
145+
}
146+
147+
.stream-list__item {
148+
background: #FFF9EA;
149+
}
150+
151+
.stream-list__item.viewed {
152+
background: transparent;
153+
}

popup.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html style="min-width: 600px;">
2+
<head>
3+
<meta charset="utf-8">
4+
<link rel="stylesheet" href="popup.css">
5+
</head>
6+
<body>
7+
<div id="popup" class="notify-stream"></div>
8+
<script src="jquery.js"></script>
9+
<script src="popup.js"></script>
10+
</body>
11+
</html>

popup.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var bg = chrome.extension.getBackgroundPage();
2+
3+
bg.getNotifications(function(data) {
4+
var $html = $(data);
5+
if ($html.find('.stream-list').length === 0) {
6+
alert('未登录');
7+
chrome.tabs.create({ url: 'https://segmentfault.com/user/login' });
8+
}
9+
$('#popup').append($html.find('.stream-list').html());
10+
});
11+
12+
$('#popup').on('click', 'a', function() {
13+
var $this = $(this);
14+
var href = $this.attr('href');
15+
if (href.substring(0, 1) === '/' && href.substring(0, 2) !== '//') {
16+
href = 'https://segmentfault.com' + href;
17+
}
18+
chrome.tabs.create({ url: href });
19+
return false;
20+
});

screenshot.png

134 KB
Loading

0 commit comments

Comments
 (0)