Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix opening of comments and links.

  • Loading branch information...
commit 1d460d7b8c55abb896f7676d840a849273a0ad44 1 parent 87b89c4
Russell Davis russelldavis authored
2  README.textile
View
@@ -4,4 +4,4 @@ Install the extension: "hacker news hotkeys extension":https://chrome.google.com
This extension uses jQuery to add hotkeys to "news.ycombinator.com":http://news.ycombinator.com/
-Most of the action goes on in hnkeys.js, the "content script." The extension uses background.html to open new tabs.
+Most of the action goes on in hnkeys.js, the "content script." The extension uses background.js to open new tabs.
42 background.html → background.js
View
@@ -1,27 +1,15 @@
-<html>
-<head>
-
-<script type="text/javascript">
-
-chrome.extension.onRequest.addListener(
- function(request, sender, sendResponse) {
- // if (request.localstorage == "gmail")
- // sendResponse({style: localStorage.email});
- // else
- // Open a new friggin tab.
- if (request.opentab) {
- chrome.tabs.create({
- url: request.opentab
- });
- sendResponse({});
- } else {
- sendResponse({}); // snub them.
- }
- });
-
-</script>
-</head>
-
-<body></body>
-
-</html>
+chrome.runtime.onMessage.addListener(
+ function(request, sender, sendResponse) {
+ // if (request.localstorage == "gmail")
+ // sendResponse({style: localStorage.email});
+ // else
+ // Open a new friggin tab.
+ if (request.opentab) {
+ chrome.tabs.create({
+ url: request.opentab
+ });
+ sendResponse({});
+ } else {
+ sendResponse({}); // snub them.
+ }
+ });
4 hnkeys.js
View
@@ -54,7 +54,7 @@ function openComments (titlerow) {
// Items pages — when title is selected, opens the article
if (path === '/item') {
link = titlerow.find('.title a').first();
- link && chrome.extension.sendRequest({opentab: link.attr('href')});
+ link && chrome.runtime.sendMessage({opentab: link.attr('href')});
console.log('tried to open '+link.text());
// Front page and other pages — warning: may be broken on other pages
@@ -69,7 +69,7 @@ function openComments (titlerow) {
window.location = 'http://news.ycombinator.com'+ link.attr('href');
} else {
console.log('opened');
- chrome.extension.sendRequest({opentab: 'http://news.ycombinator.com/'+ link.attr('href')});
+ chrome.runtime.sendMessage({opentab: 'http://news.ycombinator.com/'+ link.attr('href')});
}
}
}
2  manifest.json
View
@@ -9,7 +9,7 @@
, "browser_action": { "default_icon": "images/hnkeys128.png" }
-, "background": { "page": "background.html" }
+, "background": { "scripts": ["background.js"] }
, "permissions": [ "tabs" ]
Please sign in to comment.
Something went wrong with that request. Please try again.