Skip to content

Commit

Permalink
Add options
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasthiebaud committed Apr 20, 2018
1 parent defe7d5 commit 54749c7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
19 changes: 15 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
function getOptions() {
return browser.storage.sync.get();
}

browser.runtime.onMessage.addListener(function(message) {
switch(message.type) {
case 'notification':
browser.notifications.create(message.id, {
message: message.content,
title: message.title,
type: 'basic',
getOptions().then((options) => {
if (options.notifications) {
browser.notifications.create(message.id, {
message: message.content,
title: message.title,
type: 'basic',
});
}
});
break;
case 'options':
return getOptions();
break;
}
});
17 changes: 11 additions & 6 deletions git.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ function copy(text) {
try {
const success = document.execCommand('copy');
if (success) {
console.log('[Trello Branch Name] Branch name successfully copied to clipboard');
console.debug('[Trello Branch Name] Branch name successfully copied to clipboard');
} else {
console.log('[Trello Branch Name] Copy to clipboard failed');
console.debug('[Trello Branch Name] Copy to clipboard failed');
}
} catch (err) {
console.log('[Trello Branch Name] Copy to clipboard failed', err);
console.debug('[Trello Branch Name] Copy to clipboard failed', err);
}

document.body.removeChild(clipboard);
Expand Down Expand Up @@ -72,11 +72,16 @@ function createIcon(title) {
}

document.arrive('.badges', { existing: true },function() {
const title = this.previousElementSibling.innerText;

if (this.querySelector('img.badge')) {
return;
}

this.appendChild(createIcon(title));
let title = this.previousElementSibling.innerText;
browser.runtime.sendMessage({ type: 'options' }).then((options) => {
if (options.hash) {
title = this.previousElementSibling.textContent;
}

this.appendChild(createIcon(title));
})
})
14 changes: 12 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Trello branch name",
"version": "1.5",
"version": "1.6",
"description": "Add a button on each trello card to create a git branch name from the card name",
"icons": {
"48": "images/icon_48.png",
Expand All @@ -16,9 +16,19 @@
],
"permissions": [
"clipboardWrite",
"notifications"
"notifications",
"storage"
],
"background": {
"scripts": ["background.js"]
},
"options_ui": {
"page": "options.html",
"browser_style": true
},
"applications": {
"gecko": {
"id": "{34385045-f80b-464b-980b-13f47e101692}"
}
}
}
23 changes: 23 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>

<body>
<form>
<div>
<input type="checkbox" id="notifications" name="notifications" checked>
<label for="notifications">Send notifications</label>
</div>
<div>
<input type="checkbox" id="hash" name="hash">
<label for="hash">Include hash</label>
</div>
<div>
<button type="submit">Save</button>
</div>
</form>
<script src="options.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function saveOptions(e) {
browser.storage.sync.set({
hash: document.querySelector("#hash").checked,
notifications: document.querySelector("#notifications").checked,
useCustomOptions: true,
});
e.preventDefault();
}

function restoreOptions() {
const gettingItem = browser.storage.sync.get();
gettingItem.then((res) => {
if (res.useCustomOptions) {
document.querySelector("#hash").checked = res.hash;
document.querySelector("#notifications").checked = res.notifications;
}
});
}

document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);

0 comments on commit 54749c7

Please sign in to comment.