Skip to content

Commit

Permalink
Open HN links inside the app instead of redirecting to news.ycombinat…
Browse files Browse the repository at this point in the history
…or.com.
  • Loading branch information
nfvs committed Jan 30, 2013
1 parent 73c3fe3 commit cc8b86a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js/hn.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,19 @@
div.innerHTML = html;

// Make all links open in new tab/window
// If the link is HN internal, redirect to the webapp page
var itemid_regex = /http[s]?:\/\/news.ycombinator.com\/item\?id=([0-9]+)/;
var links = div.querySelectorAll('a');
for (var i=0, l=links.length; i<l; i++){
links[i].target = '_blank';
var m=links[i].href.match(itemid_regex);
if (m && m[1]){
links[i].href = '#/item/' + m[1];
} else {
links[i].target = '_blank';
}
}


// 20K chars will be the max to trigger collapsible comments.
// I can use number of comments as the condition but some comments
// might have too many chars and make the page longer.
Expand Down

0 comments on commit cc8b86a

Please sign in to comment.