diff --git a/background.js b/background.js index 847063d..d8dbd5c 100644 --- a/background.js +++ b/background.js @@ -1,6 +1,7 @@ - -// Add listener for pageaction -chrome.pageAction.onClicked.addListener(function(tab) { +/** +* Listener Callbacks +*/ +var pageActionListener = function(tab) { var destination, commentURL, tabId, @@ -16,19 +17,18 @@ chrome.pageAction.onClicked.addListener(function(tab) { // navigate tab to new url chrome.tabs.update(tabId, {url: destination}); -}); +} -// listens for messages passed when chrome storage is altered -chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { + +var messageListener = function(message, sender, sendResponse) { var tabName; clickFlag = true; mostRecentComment = message; -}); +} -// tab change listener runs URL checking function -chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { +var tabUpdateListener = function(tabId, changeInfo, tab) { var isLoading, tabName; @@ -46,9 +46,19 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { // turn clickFlag off clickFlag = false; } -} ); +} -// create array to which all scraped pages are pushed + +/** +* Vars and Events +*/ var tabList = Object(), mostRecentComment, clickFlag; + +// Add listener for pageaction +chrome.pageAction.onClicked.addListener( pageActionListener ); +// listens for messages passed when chrome storage is altered +chrome.runtime.onMessage.addListener( messageListener ); +// tab change listener runs URL checking function +chrome.tabs.onUpdated.addListener( tabUpdateListener ); diff --git a/hackernews.js b/hackernews.js index a6bab1b..0fc95ba 100644 --- a/hackernews.js +++ b/hackernews.js @@ -1,4 +1,6 @@ -// takes a post link and returns its comment url +/** +* Functions +*/ function getCommentURL( linkToPost ) { var postCell, postRow, @@ -37,6 +39,15 @@ function nodelistToArray( nodelist ) { return array; } +// send comment url +function messenger( message ) { + chrome.runtime.sendMessage( message ); +} + + +/** +* Vars and Events +*/ var linkList, linkArray; @@ -44,11 +55,6 @@ var linkList, linkList = document.querySelectorAll( "td.title a" ); linkArray = nodelistToArray( linkList ); -function messenger( message ) { - // send comment url - chrome.runtime.sendMessage( message ); -} - // use < to omit "more" for (var i = 0; i < linkArray.length; i++) { var link, @@ -63,6 +69,3 @@ for (var i = 0; i < linkArray.length; i++) { } }; - - - diff --git a/manifest.json b/manifest.json index 03da5d8..79105f8 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Back to the Comments", "description": "When browsing hacker news this extension allows users to quickly navigate back to the comments of an item once it has been clicked through to.", - "version": "0.2.1", + "version": "0.3.0", "permissions": [ "tabs","","storage"