Skip to content

Commit

Permalink
Add option to allow desktop notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Jul 21, 2017
1 parent 66adbdd commit fe61c75
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
16 changes: 11 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const notificationsUrl = "https://github.com/notifications";
var count = 0;

browser.storage.local.get('accessToken')
browser.storage.local
.get({
accessToken: '',
showNotifications: false
})
.then((options) => {
let accessToken = options.accessToken || '';

function update() {
if (!accessToken) {
if (!options.accessToken) {
return;
}

fetch('https://api.github.com/notifications?access_token=' + accessToken, {
fetch(`https://api.github.com/notifications?access_token=${options.accessToken}`, {
cache: 'reload'
})
.then((response) => {
Expand All @@ -26,6 +28,10 @@ browser.storage.local.get('accessToken')

count = notifications.length;

if (!options.showNotifications) {
return;
}

if (!count) {
return;
}
Expand Down
9 changes: 7 additions & 2 deletions options/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
<form>
<fieldset>
<legend>Options</legend>
<label for="access-token">Access Token</label>
<input type="text" name="access_token" id="access-token">
<p>
<label for="access-token">Access Token</label>
<input type="text" name="access_token" id="access-token">
</p>
<p>
<input type="checkbox" name="show_notifications" id="show-notifications"> Show desktop notifications
</p>
<button type="submit">Save</button>
</fieldset>
</form>
Expand Down
17 changes: 11 additions & 6 deletions options/page.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
document.addEventListener('DOMContentLoaded', () => {
var accessToken = browser.storage.local.get('accessToken');

accessToken.then((options) => {
document.querySelector('#access-token').value = options.accessToken || '';
});
browser.storage.local
.get({
accessToken: '',
showNotifications: false
})
.then((options) => {
document.querySelector('#access-token').value = options.accessToken;
document.querySelector('#show-notifications').checked = options.showNotifications;
});
});
document.querySelector('form')
.addEventListener('submit', (e) => {
e.preventDefault();

browser.storage.local.set({
accessToken: document.querySelector('#access-token').value
accessToken: e.target['access_token'].value,
showNotifications: e.target['show_notifications'].checked
});
});

0 comments on commit fe61c75

Please sign in to comment.