Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
phocks committed May 16, 2019
1 parent 2f3772f commit c1982e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ function restoreOptions() {
}

document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
24 changes: 13 additions & 11 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const parser = require('fast-xml-parser');
const parser = require("fast-xml-parser");

let stories;
let openedStories = [];
Expand All @@ -8,28 +8,31 @@ let options = {};

const getLatest = () => {
// Fetches latest story and sets it in global
fetch('https://newsy.glitch.me/api/rss')
fetch("https://newsy.glitch.me/api/rss")
.then(res => res.text())
.then(text => {
const jsonObj = parser.parse(text);
stories = jsonObj.rss.channel.item;

// Wait till we get the stories otherwise it doesn't
// seem to get storage
const storage = browser.storage.sync.get();
storage.then(
gotOptions => {
options = gotOptions;

if (options.count === 'true') {
if (options.count === "true") {
updateStoryCount();
} else {
browser.browserAction.setBadgeText({ text: '' });
browser.browserAction.setBadgeText({ text: "" });
}
},
() => console.log('Error getting options')
() => console.error("Error getting options")
);
});
};

// Counts how many new stories since last story
function updateStoryCount() {
if (openedStories.length > 0) {
newStoryCount = 0;
Expand All @@ -39,7 +42,7 @@ function updateStoryCount() {
}
}

if (newStoryCount === 0) browser.browserAction.setBadgeText({ text: '' });
if (newStoryCount === 0) browser.browserAction.setBadgeText({ text: "" });
else browser.browserAction.setBadgeText({ text: newStoryCount.toString() });
}

Expand Down Expand Up @@ -70,7 +73,7 @@ browser.browserAction.onClicked.addListener(function() {
// Don't let array get too big
if (openedStories.length > 256) openedStories.shift();

if (options.newtab === 'true') {
if (options.newtab === "true") {
browser.tabs
.create({
url: nextStory
Expand All @@ -82,15 +85,15 @@ browser.browserAction.onClicked.addListener(function() {
}

// Only update if we want to show article count
if (options.count === 'true') {
if (options.count === "true") {
newStoryCount--;
if (newStoryCount < 0) newStoryCount = 0;
if (newStoryCount === 0) browser.browserAction.setBadgeText({ text: '' });
if (newStoryCount === 0) browser.browserAction.setBadgeText({ text: "" });
else browser.browserAction.setBadgeText({ text: newStoryCount.toString() });
}
});

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

browser.alarms.onAlarm.addListener(alarmInfo => {
getLatest();
Expand All @@ -103,7 +106,6 @@ const getChangedOptions = (changes, area) => {
options = { ...options, [item]: changes[item].newValue };
}

console.log(options);
getLatest();
};

Expand Down

0 comments on commit c1982e7

Please sign in to comment.