Skip to content

paulo0812/hackernews-button

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Embeddable Hacker News vote / counter button

HN Button

Async, embeddable submit + vote counter button for Hacker News.

  • If the story has not been posted to HN, "Submit" button is shown, otherwise latest point count is displayed.
  • Auto-detects Google Analytics and registers clicks events (see reports under Traffic Sources > Social > Social Plugins).

Embedding the button

Step 1, place the HN link where you want the button appear on the page:

<!-- Auto-detect URL of current page and title if necessary -->
<a href="http://news.ycombinator.com/submit" class="hn-share-button">Vote on HN</a>

<!-- Override the URL and Title for the button -->
<a href="http://news.ycombinator.com/submit" class="hn-share-button" data-title="Some Title" data-url="http://www.igvita.com/">Vote on HN</a>

Step 2, add the following loader snippet right before the </body> tag:

<script>
	(function() {
	   var hn = document.createElement('script'); hn.type = 'text/javascript';
	   hn.async = true; hn.src = 'http://hnbutton.appspot.com/static/hn.js';
	   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(hn, s);
	})();
</script>

Note: you can safely embed multiple buttons on the same page.

Misc

  • Kudos to @sbashyal and @stbullard for the button styling (hnlike.com)
  • (MIT License) - Copyright (c) 2012 Ilya Grigorik

About

Embeddable Hacker News button + vote counter for your site

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published