Skip to content

Commit

Permalink
Actually works
Browse files Browse the repository at this point in the history
  • Loading branch information
phocks committed May 16, 2019
1 parent 57f3e41 commit fa72555
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
<html>
<head>
<meta charset="utf-8" />
<style>

</style>
</head>
<body>
<form>
<label>Open articles in new tab: <input type="text" id="newtab"/></label>
<br />
<label>Show new article count: <input type="text" id="count"/></label>
<button type="submit">Save</button>
</form>
Expand Down
17 changes: 12 additions & 5 deletions options.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
function saveOptions(e) {
e.preventDefault();
browser.storage.sync.set({
newtab: document.querySelector("#newtab").value
newtab: document.querySelector("#newtab").value,
count: document.querySelector("#count").value
});
}

function restoreOptions() {

function setCurrentChoice(result) {
function setNewTab(result) {
document.querySelector("#newtab").value = result.newtab || "false";
}

function setCount(result) {
document.querySelector("#count").value = result.count || "true";
}

function onError(error) {
console.log(`Error: ${error}`);
}

var getting = browser.storage.sync.get("newtab");
getting.then(setCurrentChoice, onError);
const newtab = browser.storage.sync.get("newtab");
newtab.then(setNewTab, onError);

const count = browser.storage.sync.get("count");
count.then(setCount, onError);
}

document.addEventListener("DOMContentLoaded", restoreOptions);
Expand Down
8 changes: 6 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ const getLatest = () => {
function updateStoryCount() {
newStoryCount = 0;

if (openedStories > 0) {
if (openedStories.length > 0) {
for (let story of stories) {
console.log(story.link);
if (story.link === openedStories[openedStories.length - 1]) break;
else newStoryCount++;
}
Expand All @@ -33,7 +34,7 @@ function updateStoryCount() {

if (newStoryCount === 0)
browser.browserAction.setBadgeText({
text: '0'
text: ''
});
else browser.browserAction.setBadgeText({ text: newStoryCount.toString() });
}
Expand Down Expand Up @@ -77,6 +78,9 @@ browser.browserAction.onClicked.addListener(function() {
}

newStoryCount = 0;
browser.browserAction.setBadgeText({
text: ''
});
});

browser.alarms.create('get-stories', { periodInMinutes: 1 });
Expand Down

0 comments on commit fa72555

Please sign in to comment.