├── .gitignore
├── LICENSE
├── README.md
├── Rakefile
├── _locales
├── en
│ └── messages.json
├── zh_CN
│ └── messages.json
└── zh_TW
│ └── messages.json
├── background.html
├── background.js
├── config.js
├── icon.png
├── icon128.png
├── icon16.png
├── manifest.json
├── options.css
├── options.html
├── options.js
├── resources
└── screenshot-2.png
└── style.css
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.zip
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Cam Song
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | 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, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | PHPHub Notifier
2 | ==================
3 | Chrome extension to enhance PHPHub experiences.
4 |
5 | ## Thanks to
6 |
7 | > [GitHub Mate](https://github.com/camsong/chrome-github-mate) and its author [Cam Song](https://github.com/camsong).
8 |
9 | ### Install
10 |
11 | https://chrome.google.com/webstore/detail/phphub-notifier/fcopfkdgikhodlcjkjdppdfkbhmehdon
12 |
13 | ### Features
14 |
15 | #### 1. Notify you when interesting thing is happening at PHPHub.
16 |
17 | ### License
18 |
19 | Released under the terms of MIT License
20 |
21 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | namespace :chrome do
2 | desc 'build chrome zip file'
3 | task :zip do
4 | puts 'building zip for chrome...'
5 | sh %{ zip -r chrome-phphub-notifier.zip _locales/ manifest.json *.png *.js *.html *.css }
6 | puts 'build done.'
7 | end
8 | end
9 |
10 | task default: 'chrome:zip'
11 |
12 |
--------------------------------------------------------------------------------
/_locales/en/messages.json:
--------------------------------------------------------------------------------
1 | {"github_login_needed":{"message":"You must login to PHPHub in order to use this extension."}}
2 |
--------------------------------------------------------------------------------
/_locales/zh_CN/messages.json:
--------------------------------------------------------------------------------
1 | {"github_login_needed":{"message":"\u8BF7\u5148\u767B\u5F55PHPHub"}}
2 |
--------------------------------------------------------------------------------
/_locales/zh_TW/messages.json:
--------------------------------------------------------------------------------
1 | {"github_login_needed":{"message":"\u8ACB\u5148\u767B\u9304PHPHub"}}
2 |
--------------------------------------------------------------------------------
/background.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/background.js:
--------------------------------------------------------------------------------
1 | ;(function(){
2 | 'use strict';
3 |
4 | // message listener to accept request from content script
5 | chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
6 | console.log('get message request: key=' + request.key);
7 | sendResponse({result: getConfig()[request.key]});
8 | });
9 |
10 | var GitHubNotification;
11 | var notificationCountUrl = 'https://laravel-china.org/notifications/count';
12 | var notificationUrl = 'https://laravel-china.org/notifications';
13 | var blue = [1, 128, 255, 255];
14 | var gray = [190, 190, 190, 230];
15 |
16 | function _isNotificationUrl(url) {
17 | return url.indexOf(notificationUrl) === 0;
18 | }
19 |
20 | function _goToNotificationTab() {
21 | _displayUnreadCount(0);
22 | console.log('Going to notification tab...');
23 | chrome.tabs.getAllInWindow(undefined, function(tabs) {
24 | for (var i = 0, tab; tab = tabs[i]; i++) {
25 | if (tab.url && _isNotificationUrl(tab.url)) {
26 | console.log('Found notification tab: ' + tab.url + '. ' +
27 | 'Focusing and refreshing count...');
28 | chrome.tabs.update(tab.id, {selected: true});
29 | GitHubNotification.checkNotifications();
30 | return;
31 | }
32 | }
33 | console.log('Could not find notification tab. Creating one...');
34 | chrome.tabs.create({url: notificationUrl});
35 | });
36 | }
37 |
38 | function _loginWarning() {
39 | chrome.browserAction.setBadgeBackgroundColor({color: gray});
40 | chrome.browserAction.setBadgeText({text: '?'});
41 | chrome.browserAction.setTitle({title: chrome.i18n.getMessage("github_login_needed")});
42 | }
43 |
44 | function _getBadgeText(num) {
45 | return num != 0 ? num+'' : ''
46 | }
47 |
48 | function _getTitle(num) {
49 | return num + " unread " +
50 | (num == 1 ? 'notification' : 'notifications');
51 | }
52 |
53 | function _displayUnreadCount(response) {
54 | var unreadCount = parseInt(response);
55 | unreadCount = isNaN(unreadCount) ? 0 : unreadCount;
56 | console.log('Get ' + unreadCount + ' unread notifications');
57 |
58 | chrome.browserAction.setBadgeBackgroundColor({color: blue});
59 | chrome.browserAction.setBadgeText({text: _getBadgeText(unreadCount)});
60 |
61 | chrome.browserAction.setTitle({title: _getTitle(unreadCount)});
62 | }
63 |
64 | GitHubNotification = {
65 | getInterval: function() {
66 | return parseInt(getConfig()['feature-2-interval']) * 60 * 1000;
67 | },
68 |
69 | isEnabled: function() {
70 | return getConfig()['feature-2-enable'];
71 | },
72 |
73 | init: function() {
74 | this.checkNotificationsLoop();
75 |
76 | chrome.browserAction.onClicked.addListener(this.goToNotificationTab.bind(this));
77 | },
78 |
79 | goToNotificationTab: _goToNotificationTab,
80 |
81 | checkNotificationsLoop: function(){
82 | // check notification again if it's enabled and the date range since last checked is longer
83 | // than interval.
84 | if (GitHubNotification.isEnabled() && (
85 | typeof(localStorage.last_checked_date) === 'undefined' ||
86 | (Date.now() - localStorage.last_checked_date) >= GitHubNotification.getInterval()
87 | )) {
88 | this.checkNotifications();
89 | localStorage.last_checked_date = Date.now();
90 | }
91 |
92 | // loop;
93 | window.setTimeout(GitHubNotification.checkNotificationsLoop.bind(GitHubNotification), 60000);
94 | },
95 |
96 | checkNotifications: function() {
97 | var xhr = new XMLHttpRequest();
98 | xhr.onreadystatechange = function() {
99 | if (xhr.readyState == 4) {
100 | var response = xhr.response;
101 |
102 | if (response.match(/
Features list | 18 ||
---|---|
Show notifications number | 23 |24 | | 26 |
29 | 39 | | 40 |