Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added: Inline commenting thanks to Samuel Stern

Added: Upvote arrows to index pages, hopefully works for downvotes too
Fix: Updated to manifest version 2
  • Loading branch information...
commit 4e3931e3573b8a6e11a2aeba700c8893643cb2d1 1 parent 742085a
etcet authored
View
2  LICENSE
@@ -1,6 +1,6 @@
Hacker News Enhancement Suite
Copyright (C) 2012 Chris James
-Using code from Wayne Larson and @jarques, with permission to release under MIT License
+Using code from Wayne Larson, @jarques, and Samuel Stern, with permission to release under MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
View
3  README.md
@@ -9,6 +9,7 @@ Features
* Easy access to all pages
* Enhanced comment threads
* Collapsible comments
+ * Inline commenting
* Link to parent
* Display all comments on paginated threads
* Highlight the original poster
@@ -44,3 +45,5 @@ Thanks
Wayne Larson for hckrnews.com and permission to use code from his extension which displays new comments.
@jarques for his HN+ extension (https://github.com/jarquesp/Hacker-News--) which was used as a starting point for this project.
+
+Thanks to Samuel Stern for the inline commenting.
View
27 background.js
@@ -0,0 +1,27 @@
+// Add event listeners
+chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
+ console.log('REQUEST', request.method, request)
+ if (request.method == "getAllLocalStorage") {
+ sendResponse({data: localStorage});
+ }
+ else if (request.method == "getLocalStorage") {
+ sendResponse({data: localStorage[request.key]});
+ }
+ else if (request.method == "setLocalStorage") {
+ localStorage[request.key] = request.value;
+ sendResponse({});
+ }
+ else {
+ sendResponse({});
+ }
+});
+
+//expire old entries
+(function() {
+ for (i=0; i<localStorage.length; i++) {
+ var info = JSON.parse(localStorage[localStorage.key(i)]);
+ var now = new Date().getTime();
+ if (now > info.expire)
+ localStorage.removeItem(localStorage.key(i));
+ }
+});
View
32 background_chrome.html
@@ -1,32 +0,0 @@
-<html>
- <!--<script src="shared.js" type="text/javascript"></script>-->
- <script>
- // Add event listeners
- chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
- console.log('REQUEST', request.method, request)
- if (request.method == "getAllLocalStorage") {
- sendResponse({data: localStorage});
- }
- else if (request.method == "getLocalStorage") {
- sendResponse({data: localStorage[request.key]});
- }
- else if (request.method == "setLocalStorage") {
- localStorage[request.key] = request.value;
- sendResponse({});
- }
- else {
- sendResponse({});
- }
- });
-
- //expire old entries
- (function() {
- for (i=0; i<localStorage.length; i++) {
- var info = JSON.parse(localStorage[localStorage.key(i)]);
- var now = new Date().getTime();
- if (now > info.expire)
- localStorage.removeItem(localStorage.key(i));
- }
- });
- </script>
-</html>
View
113 js/hn.js
@@ -10,9 +10,97 @@
* hckrnews.com extension - http://hckrnews.com/about.html
* by Wayne Larson (wvl)
*
+* Thanks to Samuel Stern for the inline replying
+*
* Under MIT license, see LICENSE
*/
+var InlineReply = {
+ init: function() {
+ $('a[href^="reply?"]').click(function(e) {
+ e.preventDefault();
+
+ //make sure there's no stray underlining between Reply and Cancel
+ $(this).addClass('underlined');
+ $(this).parent('u').replaceWith($(this));
+
+ /*remove the 'reply' link without actually hide()ing it because it
+ doesn't work that way with collapsible comments*/
+ $(this).addClass('no-font-size');
+
+ domain = window.location.origin;
+ link = domain + '/' + $(this).attr('href');
+
+ if ($(this).next().hasClass('replyform')) {
+ $(this).next().show();
+ }
+ else {
+ //add buttons and box
+ $(this).after(
+ '<div class="reply_form"> \
+ <textarea rows="4" cols="60"/> \
+ <input type="submit" value="Reply" class="rbutton"/> \
+ <input type="submit" value="Cancel" class="cbutton"/> \
+ </div>'
+ );
+ $(this).parent().find('.rbutton').attr('data', link);
+ }
+ });
+
+ $('.rbutton').live('click', function(e) {
+ e.preventDefault();
+ link = $(this).attr('data');
+ text = $(this).prev().val();
+ InlineReply.postCommentTo(link, domain, text, $(this));
+ });
+
+ $('.cbutton').live('click', function(e) {
+ InlineReply.hideButtonAndBox($(this).prev());
+ });
+ },
+
+ postCommentTo: function(link, domain, text, button) {
+ InlineReply.disableButtonAndBox(button);
+ $.ajax({
+ accepts: "text/html",
+ url: link
+ }).success(function(html) {
+ input = $(html).find('input');
+ fnid = input.attr('value');
+ InlineReply.sendComment(domain, fnid, text);
+ }).error(function(xhr, status, error) {
+ InlineReply.enableButtonAndBox(button);
+ });
+ },
+
+ sendComment: function(domain, fnidarg, textarg) {
+ $.post(
+ domain + "/r",
+ {fnid : fnidarg, text: textarg }
+ ).complete(function(a) {
+ window.location.reload(true);
+ });
+ },
+
+ disableButtonAndBox: function(button) {
+ button.attr('disabled', 'disabled');
+ button.next().attr('disabled', 'disabled');
+ button.prev().attr('disabled', 'disabled');
+ },
+
+ enableButtonAndBox: function(button) {
+ button.removeAttr('disabled');
+ button.next().removeAttr('disabled');
+ button.prev().removeAttr('disabled');
+ },
+
+ hideButtonAndBox: function(button) {
+ button.parent().prev().removeClass('no-font-size');
+ button.parent().hide();
+ }
+}
+
+
var CommentTracker = {
init: function() {
var page_info = CommentTracker.getInfo();
@@ -126,9 +214,9 @@ var CommentTracker = {
}
});
}
-
}
+
var RedditComments = {
init: function(comments) {
var collapse_button = $('<span/>').addClass('collapse')
@@ -190,7 +278,7 @@ var RedditComments = {
if (link_to_parent.attr('href').length > 1)
return;
- var el = $(this).closest("table");
+ var el = $(this).closest("table");
var level = el.attr('level');
var prev_level = level;
var comment_row = el.parent().parent();
@@ -208,8 +296,8 @@ var RedditComments = {
},
collapse: function(e) {
- var $e = $(e.target);
- var el = $e.closest("table");
+ var $e = $(e.target);
+ var el = $e.closest("table");
var comment_row = el.parent().parent();
var indent = Number(el.attr('level'));
//var indent = RedditComments.stripPx(comment_row.find('td:eq(1) img').css('width'));
@@ -253,7 +341,7 @@ var RedditComments = {
var def = el.find('.default');
if (has_visible_children || !el.hasClass('collapsed')) {
var child_str = (num_children > 0 ? " (" + num_children + " child" + (num_children == 1? "" : "ren") + ")" : "");
- $e.text("[+]" + child_str)
+ $e.text("[+]" + child_str)
.attr('title', 'Restore comment')
.css('margin-left', def.prev().width() + 2 + 'px');
def.find('div').siblings().hide();
@@ -261,17 +349,17 @@ var RedditComments = {
el.addClass('collapsed');
}
else {
- $e.text("[−]")
+ $e.text("[−]")
.attr('title', 'Collapse comment')
.css('margin-left', '');
def.find('div').siblings().show();
def.prev().show();
el.removeClass('collapsed');
}
- }
-
+ }
}
+
var HN = {
init: function() {
@@ -425,7 +513,9 @@ var HN = {
HN.init_keys();
- HN.removeUpvotes();
+ //HN.removeUpvotes();
+ //with upvotes, the 'more' link needs to be shifted 1 more col
+ HN.moveMoreLink();
HN.formatScore();
HN.formatURL();
@@ -445,6 +535,7 @@ var HN = {
},
doCommentsList: function(pathname, track_comments) {
+ InlineReply.init();
HN.addClassToCommenters();
//add classes to comment page header (OP post) and the table containing all the comments
@@ -677,6 +768,9 @@ var HN = {
});
},
+ moveMoreLink: function() {
+ $('#more').prev().attr('colspan', '3');
+ },
removeUpvotes: function() {
var titles = $('.title');
if ($(titles[titles.length - 1]).attr('id') == "more")
@@ -963,6 +1057,7 @@ var HN = {
}
}
+
//show new comment count on hckrnews.com
if (window.location.host == "hckrnews.com") {
$('ul.entries li').each(function() {
View
60 js/hnreply.js
@@ -1,60 +0,0 @@
-var InlineReply = {
-
- init: function() {
- $('a[href^="reply?"]').click(function(e) {
- e.preventDefault();
- $(this).hide();
- link = 'http://news.ycombinator.com/' + $(this).attr('href');
- $(this).after(
- '<div class="replyform" style="width:300px;height:100px;position:relative;"> \
- <textarea rows="4" cols="60" style="height:60px;" /> \
- <input type ="submit" value="Reply" class="rbutton" \
- style="position:absolute;bottom:0px;left:0px;" /> \
- </div>'
- );
- $(this).parent().find('.rbutton').attr('data', link);
- });
-
- $('.rbutton').live('click', function(e) {
- e.preventDefault();
- link = $(this).attr('data');
- text = $(this).prev().val();
- InlineReply.postCommentTo(link, text, $(this));
- });
- },
-
- postCommentTo: function(link, text, button) {
- InlineReply.disableButtonAndBox(button);
- $.ajax({
- accepts: "text/html",
- url : link
- }).success(function(html) {
- input = $(html).find('input');
- fnid = input.attr('value');
- InlineReply.sendComment(fnid, text);
- }).error(function(xhr, status, error) {
- InlineReply.enableButtonAndBox(button);
- });
- },
-
- sendComment: function(fnidarg, textarg) {
- $.post(
- "http://news.ycombinator.com/r",
- {fnid : fnidarg, text: textarg }
- ).complete(function(a) {
- window.location.reload(true);
- });
- },
-
- disableButtonAndBox: function(button) {
- button.attr('disabled','disabled');
- button.prev().attr('disabled', 'disabled');
- },
-
- enableButtonAndBox: function(button) {
- button.removeAttr('disabled');
- button.prev().removeAttr('disabled');
- }
-}
-
-InlineReply.init();
View
10 manifest.json
@@ -2,7 +2,10 @@
"name": "Hacker News Enhancement Suite",
"version": "1.1.1",
"description": "Hacker News Enhanced.",
- "background_page": "background_chrome.html",
+ "manifest_version": 2,
+ "background": {
+ "scripts": ["background.js"]
+ },
"permissions": ["tabs"],
"icons": {
"16" : "images/icon-16.png",
@@ -29,11 +32,6 @@
"matches": ["http://hckrnews.com/*"],
"run_at": "document_end",
"js": ["js/jquery-1.7.2.js", "js/hn.js"]
- },
- {
- "matches" : ["http://news.ycombinator.com/item?*"],
- "run_at" : "document_end",
- "js" : ["js/jquery-1.7.2.min.js", "js/hnreply.js"]
}
]
}
View
38 style.css
@@ -114,7 +114,7 @@ table tr td {
padding-bottom: 5px;
}
#index-body .title {
- padding-left: 18px;
+ padding-left: 8px;
padding-right: 18px;
}
/*comments tally hover*/
@@ -255,6 +255,14 @@ body#item-body .title {
top: -4px;
position-right: 3px;
}
+/*upvotes on index page*/
+#index-body #content td:nth-child(3) {
+ width: 30px;
+}
+#index-body #content td:nth-child(3) center {
+ position: absolute;
+ top: 5px;
+}
/* poll vote ups */
#item-body .item-header tr:last-child img[src="http://ycombinator.com/images/grayarrow.gif"],
#item-body .item-header tr:last-child img[src="/sslyc/images/grayarrow.gif"] {
@@ -279,9 +287,9 @@ input[type="submit"] {
font-size: 13px;
color: white;
background: -webkit-gradient(linear,left top,left bottom,from(#d74937),to(#c23422));
- border: 1px solid #666;
padding: 5px 10px;
text-transform: capitalize;
+ border: 1px solid #666;
border-radius: 2px;
}
input[type="submit"]:hover {
@@ -297,7 +305,7 @@ font[color="#ff6600"] {
}
.title a.on_story {
- border-left: 2px solid #3986f8 !important;
+ border-left: 2px solid #3986f8 !important;
}
.title a:visited {opacity: .5;}
@@ -401,11 +409,14 @@ form textarea {
height:80px;
overflow: auto;
}
-input[name="q"], input[type="text"], form textarea {
- border-color: #d74937 !important;
+textarea, input {
border-width: 1px;
border-radius: 2px;
}
+form textarea:focus, textarea:focus, input:focus, input[name="q"] {
+ outline: #d74937;
+ border-color: #d73937 !important;
+}
form[action="http://www.hnsearch.com/search#request/all"],
input[name="q"] {
width: 270px;
@@ -421,7 +432,7 @@ input[name="q"]:focus {
}
form[action="http://www.hnsearch.com/search#request/all"] {
margin: 0 auto;
- color: #fff;
+ color: #fff;
}
html body center table tbody tr td table tbody tr td table {
background: none !important
@@ -488,6 +499,9 @@ img[src="http://ycombinator.com/images/grayarrow.gif"],
img[src="/sslyc/images/grayarrow.gif"] {
width: 10px;
}
+.reply_form {
+ width: 300px;
+}
#options_bar {
position: fixed;
@@ -529,9 +543,12 @@ form[action="/r"],
form[action="/r"] input[type="text"],
form[action="/r"] textarea {
width: 385px;
- padding: 5px;
+// padding: 5px;
margin: 5px 0;
}
+form[action="/r"] input[type="submit"] {
+ margin: 0px;
+}
#submit-overlay {
position: absolute;
background: white;
@@ -579,3 +596,10 @@ form[action="/r"] textarea {
display: block;
height: 32px;
}
+
+.underlined {
+ text-decoration: underline !important;
+}
+.no-font-size {
+ font-size: 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.