-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f9e3492
Showing
7 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.cache | ||
dist | ||
node_modules | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "ABC Stumble", | ||
"version": "1.0.0", | ||
|
||
"description": "Loads latest ABC News", | ||
|
||
"icons": { | ||
"48": "icons/abc.png" | ||
}, | ||
"browser_action": { | ||
"default_icon": "icons/abc.png", | ||
"default_title": "ABC Stumble" | ||
}, | ||
"background": { | ||
"scripts": ["browser-polyfill.js", "dist/background.js"] | ||
}, | ||
"permissions": ["alarms"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "abc-stumble", | ||
"version": "1.0.0", | ||
"description": "Stumble the ABC", | ||
"main": "dist/background.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "parcel build src/background.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@abcnews/capi-fetch": "^1.3.0", | ||
"fast-xml-parser": "^3.12.16", | ||
"regenerator-runtime": "^0.13.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const parser = require('fast-xml-parser'); | ||
|
||
let stories; | ||
let openedStories = []; | ||
|
||
const getLatest = () => { | ||
// Fetches latest story and sets it in global | ||
fetch('https://newsy.glitch.me/api/rss') | ||
.then(res => res.text()) | ||
.then(text => { | ||
const jsonObj = parser.parse(text); | ||
stories = jsonObj.rss.channel.item; | ||
}); | ||
}; | ||
|
||
function onCreated(tab) {} | ||
|
||
function onError(error) { | ||
console.log(`Error: ${error}`); | ||
} | ||
|
||
browser.browserAction.onClicked.addListener(function() { | ||
const getNextStoryLink = (stories, alreadyOpened) => { | ||
for (let story of stories) { | ||
if (alreadyOpened.includes(story.link)) continue; | ||
else return story.link; | ||
} | ||
}; | ||
|
||
const nextStory = getNextStoryLink(stories, openedStories); | ||
|
||
openedStories.push(nextStory); | ||
|
||
browser.tabs | ||
.create({ | ||
url: nextStory | ||
}) | ||
.then(onCreated, onError); | ||
}); | ||
|
||
browser.alarms.create('get-stories', { periodInMinutes: 5 }); | ||
|
||
browser.alarms.onAlarm.addListener(alarmInfo => { | ||
getLatest(); | ||
}); | ||
|
||
// Initial grab of stories on load | ||
getLatest(); |