Skip to content

Commit

Permalink
Added options page and show changelog functionality to extension.
Browse files Browse the repository at this point in the history
Closes #317.
  • Loading branch information
imolorhe committed Jun 22, 2018
1 parent c59ccb8 commit c7fe09c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
12 changes: 10 additions & 2 deletions chrome-ext-files/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@
// Open the update page after every new update
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason === 'update') {
chrome.tabs.create({ url: "https://altair.sirmuel.design/updated" }, function (tab) {
console.log("New tab launched with https://altair.sirmuel.design/updated");
chrome.storage.sync.get({
showChangeLog: true
}, function (items) {
if (items.showChangeLog) {
chrome.tabs.create({
url: "https://altair.sirmuel.design/updated"
}, function (tab) {
console.log("New tab launched with https://altair.sirmuel.design/updated");
});
}
});
}
});
Expand Down
28 changes: 28 additions & 0 deletions chrome-ext-files/js/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Saves options to chrome.storage
function save_options() {
var showChangeLog = document.getElementById('show_changelog').checked;
chrome.storage.sync.set({
showChangeLog: showChangeLog
}, function () {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function () {
status.textContent = '';
}, 750);
});
}

// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
// Use default value showChangeLog = true.
chrome.storage.sync.get({
showChangeLog: true
}, function (items) {
document.getElementById('show_changelog').checked = items.showChangeLog;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',
save_options);
7 changes: 6 additions & 1 deletion chrome-ext-files/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
"permissions": [
"http://*/",
"https://*/",
"tabs"
"tabs",
"storage"
],
"content_security_policy": "script-src 'self'; object-src 'self'",
"background": {
"scripts": ["js/background.js"]
},
"options_ui": {
"page": "options.html",
"open_in_tab": false
},
"offline_enabled": true
}
20 changes: 20 additions & 0 deletions chrome-ext-files/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Altair Options</title>
</head>

<body>
<div>
<label>
<input type="checkbox" id="show_changelog"> Show changelog on update
</label>
</div>

<div id="status"></div>
<button id="save">Save</button>

<script src="js/options.js"></script>
</body>

</html>

0 comments on commit c7fe09c

Please sign in to comment.