Skip to content

Commit

Permalink
Implemented conflict page
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayquaza01 committed Dec 17, 2018
1 parent 3da101c commit 3c388a6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
11 changes: 11 additions & 0 deletions extension/conflict.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.container {
display: flex;
flex-direction: row;
}

.col {
border: 1px solid black;
display: flex;
flex-direction: column;
flex-grow: 1;
}
19 changes: 18 additions & 1 deletion extension/conflict.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="conflict.css">
<title>Conflict</title>
</head>
<body></body>
<body>
<div class="container">
<div class="col">
<button data-mode="local">Use Local</button>
<pre class="storage"></pre>
</div>
<div class="col">
<button data-mode="sync">Use Sync</button>
<pre class="storage"></pre>
</div>
<div class="col">
<button data-mode="backup">Use Backup</button>
<pre class="storage"></pre>
</div>
</div>
<script src="conflict.js"></script>
</body>
</html>
41 changes: 41 additions & 0 deletions extension/conflict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
async function replace(e) {
let local = await browser.storage.local.get(["general_notes", "site_notes"]);
let sync = await browser.storage.sync.get(["general_notes", "site_notes"]);
let res = await browser.storage.local.get("backup");
switch (e.target.dataset.mode) {
case "local":
await browser.storage.local.remove("backup");
await browser.storage.sync.remove(["general_notes", "site_notes"]);
await browser.storage.sync.set(local);
await browser.storage.local.set({ backup: local });
break;
case "sync":
await browser.storage.local.remove("backup");
await browser.storage.local.remove(["general_notes", "site_notes"]);
await browser.storage.local.set(sync);
await browser.storage.local.set({ backup: sync });
break;
case "backup":
await browser.storage.local.remove(["general_notes", "site_notes"]);
await browser.storage.sync.remove(["general_notes", "site_notes"]);
await browser.storage.local.set(res.backup);
await browser.storage.sync.set(res.backup);
break;
}
location.reload();
}

async function main() {
let local = await browser.storage.local.get(["general_notes", "site_notes"]);
let sync = await browser.storage.sync.get(["general_notes", "site_notes"]);
let res = await browser.storage.local.get("backup");
let storage = document.getElementsByClassName("storage");
storage[0].innerText = JSON.stringify(local, null, " ");
storage[1].innerText = JSON.stringify(sync, null, " ");
storage[2].innerText = JSON.stringify(res.backup, null, " ");
}

Array.from(document.getElementsByTagName("button")).forEach(ele =>
ele.addEventListener("click", replace)
);
document.addEventListener("DOMContentLoaded", main);
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"96": "icons/icon-96.png"
},
"background": {
"scripts": ["setup.js", "third-party/psl.min.js", "site-parser.js", "sync/sync.js"]
"scripts": ["setup.js", "third-party/psl.min.js", "site-parser.js"]
},
"permissions": ["storage", "tabs", "unlimitedStorage"],
"browser_action": {
Expand Down
2 changes: 1 addition & 1 deletion extension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function restoreOptions() {
}

async function exportNotesAndOptions() {
var res = await browser.storage.local.get();
var res = await browser.storage.local.get(["general_notes", "site_notes", "options"]);
// escape tabs and newlines and encode string to prevent breakage
DOM.export.href =
"data:application/json;charset=utf-8," +
Expand Down

0 comments on commit 3c388a6

Please sign in to comment.