Skip to content

Commit

Permalink
Add backup button draft
Browse files Browse the repository at this point in the history
Needs to be embedded into iframe or otherwise
the download attribute on the a element is
ignored from Firefox due to CORS restrictions

Part of #86
  • Loading branch information
stoically committed Mar 25, 2018
1 parent 902649d commit 2048e2d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/ui/backup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="semantic/semantic.min.css">
</head>
<body>
<script src="backup.js"></script>
<div>
<button id="backupToFile" class="ui button">Back up to file</button>
</div>
</body>
</html>
10 changes: 10 additions & 0 deletions src/ui/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('backupToFile').addEventListener('click', async () => {
const storage = await browser.storage.local.get('preferences');
const a = document.createElement('a');
a.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(storage.preferences, null, 2));
a.setAttribute('download', 'preferences.txt');
a.setAttribute('type', 'text/plain');
a.dispatchEvent(new MouseEvent('click'));
});
});
7 changes: 7 additions & 0 deletions src/ui/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<link rel="stylesheet" href="semantic/semantic.min.css">
<style>
body { padding: 50px; }
iframe {
margin: 0;
border: 0;
width: 100%;
height: 50px;
}
.hidden { display: none; }
</style>
</head>
Expand Down Expand Up @@ -109,6 +115,7 @@
<div class="field">
<button id="saveContainerPreferences" class="ui button primary">Save</button>
</div>
<iframe src="backup.html"></iframe>
</form>
</div>
<div class="ui tab segment" data-tab="isolation">
Expand Down
3 changes: 1 addition & 2 deletions src/ui/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,4 @@ window.requestNotificationsPermissions = async () => {
$('#notifications')
.checkbox('uncheck');
}
};

};

0 comments on commit 2048e2d

Please sign in to comment.