Skip to content

Commit

Permalink
Add option to only show notifications count for participating issues, c…
Browse files Browse the repository at this point in the history
…lose #9
  • Loading branch information
camsong committed Sep 28, 2015
1 parent 75a81b7 commit 3458527
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
9 changes: 8 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ function _goToNotificationTab() {
});
}

// type can be unread/participating
function _extractUnreadNotifications(response) {
return parseInt(response.match(/<span class="count">([^<]+)</)[1]);
var type = getConfig()['feature-2-type'];

if (type === 'participating') {
return parseInt(response.match(/<span class="count">(\d+)</g)[1].match(/\d+/g)[0]);
}
// unread and others
return parseInt(response.match(/<span class="count">(\d+)</g)[0].match(/\d+/g)[0]);
}

function _loginWarning() {
Expand Down
7 changes: 4 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var DEFAULT_CONFIG = {
'feature-1-enable': true,
'feature-2-enable': false,
'feature-2-interval': '5'
'feature-2-interval': '5',
'feature-2-type': 'unread',
};

function mergeObject(destination, source) {
Expand All @@ -15,10 +16,10 @@ function mergeObject(destination, source) {
function getConfig() {
var config;
try {
config = mergeObject(DEFAULT_CONFIG, JSON.parse(localStorage.gm_config));
config = mergeObject(DEFAULT_CONFIG, JSON.parse(localStorage.gm_config || '{}'));
} catch (e) {
console.error(e);
config = DEFAULT_CONFIG;
}
localStorage.gm_config = JSON.stringify(config);
return config;
}
21 changes: 16 additions & 5 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ <h3>GitHub Mate → Options</h3>
</tr>
</thead>
<tbody>
<tr id='feature-1'>
<tr>
<th>Click to download file</th>
<td><label>Enable <input type='checkbox' id='feature-1-enable'></label></td>
</tr>
<tr id='feature-2'>
<th rowspan='2'>Show notifications number</th>
<tr>
<th rowspan='3'>Show notifications number</th>
<td>
<label>Enable <input type='checkbox' id='feature-2-enable'>
</td>
</tr>
<tr id="feature-2-options">
<tr>
<td>
<label> Update every
<select id='feature-2-interval'>
Expand All @@ -42,7 +42,18 @@ <h3>GitHub Mate → Options</h3>
</label>
</td>
</tr>
<tr id='feature-3'>
<tr>
<td>
<label>Show
<select id='feature-2-type'>
<option value='' disabled selected>Please Choose</option>
<option value='unread'>Unread</option>
<option value='participating'>participating</option>
</select>
</label>
</td>
</tr>
<tr>
<th>Tab Size</th>
<td>
<select id='feature-3-tab-size'>
Expand Down
3 changes: 3 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ function renderOptions() {
document.querySelector('#feature-1-enable').checked = config['feature-1-enable'];
document.querySelector('#feature-2-enable').checked = config['feature-2-enable'];
document.querySelector('#feature-2-interval').value = config['feature-2-interval'];
document.querySelector('#feature-2-type').value = config['feature-2-type'];
document.querySelector('#feature-3-tab-size').value = config['feature-3-tab-size'] || '4'; // set to 4 by default
renderOptionsStates();
}

function renderOptionsStates() {
document.querySelector('#feature-2-interval').disabled = !(document.querySelector('#feature-2-enable').checked);
document.querySelector('#feature-2-type').disabled = !(document.querySelector('#feature-2-enable').checked);
}

function storeConfig() {
localStorage.gm_config = JSON.stringify({
'feature-1-enable': document.querySelector('#feature-1-enable').checked,
'feature-2-enable': document.querySelector('#feature-2-enable').checked,
'feature-2-interval': document.querySelector('#feature-2-interval').value,
'feature-2-type': document.querySelector('#feature-2-type').value,
'feature-3-tab-size': document.querySelector('#feature-3-tab-size').value,
});
}
Expand Down

0 comments on commit 3458527

Please sign in to comment.