├── .gitignore
├── app.yaml
├── static
├── hn.min.js
└── hn.js
├── README.md
└── hnbutton
├── button.html
└── hnbutton.go
/.gitignore:
--------------------------------------------------------------------------------
1 | *.6
2 | *.8
3 | *.o
4 | *.so
5 | *.cgo?.*
6 | _cgo_*
7 | _test*
8 | *.out
9 | _obj
10 |
--------------------------------------------------------------------------------
/app.yaml:
--------------------------------------------------------------------------------
1 | application: hnbutton
2 | version: 4
3 | runtime: go
4 | api_version: go1
5 |
6 | handlers:
7 | - url: /static
8 | static_dir: static
9 |
10 | - url: /.*
11 | script: _go_app
12 |
--------------------------------------------------------------------------------
/static/hn.min.js:
--------------------------------------------------------------------------------
1 | (function(a){"use strict";var b,c=a.document,d=function(a,b){if(c.getElementsByClassName)return c.getElementsByClassName(a);var d=[],e=c.getElementsByTagName(b||"*"),f,g;a=" "+a+" ";for(f=0;f
` tag: 23 | 24 | ```html 25 | 32 | ``` 33 | 34 | _Note: you can safely embed multiple buttons on the same page._ 35 | 36 | ### Misc 37 | 38 | * Kudos to @sbashyal and @stbullard for the button styling (hnlike.com) 39 | * (MIT License) - Copyright (c) 2012 Ilya Grigorik -------------------------------------------------------------------------------- /static/hn.js: -------------------------------------------------------------------------------- 1 | /*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, curly:true, browser:true, indent:2, maxerr:50, expr:true */ 2 | (function (w) { 3 | "use strict"; 4 | var j, 5 | d = w.document, 6 | getElementsByClassName = function(match, tag) { 7 | if (d.getElementsByClassName) { 8 | return d.getElementsByClassName(match); 9 | } 10 | var result = [], 11 | elements = d.getElementsByTagName(tag || '*'), 12 | i, elem; 13 | match = " " + match + " "; 14 | for (i = 0; i < elements.length; i++) { 15 | elem = elements[i]; 16 | if ((" " + (elem.className || elem.getAttribute("class")) + " ").indexOf(match) > -1) { 17 | result.push(elem); 18 | } 19 | } 20 | return result; 21 | }, 22 | hnAnchorElements = getElementsByClassName("hn-share-button", "a"), 23 | eventMethod = w.addEventListener ? "addEventListener" : "attachEvent", 24 | eventer = w[eventMethod], 25 | messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message", 26 | base = "http://hnbutton.appspot.com/"; 27 | 28 | w._gaq || (w._gaq = []); 29 | eventer(messageEvent, function (e) { 30 | if (e.origin === base && (e.data === "vote" || e.data === "submit")) { 31 | w._gaq.push(["_trackSocial", "Hacker News", e.data]); 32 | } 33 | }, false); 34 | 35 | for (j = hnAnchorElements.length - 1; j >= 0; j--) { 36 | var anchor = hnAnchorElements[j], 37 | title = anchor.getAttribute("data-title") || d.title, 38 | url = anchor.getAttribute("data-url") || w.location.href, 39 | i = d.createElement("iframe"); 40 | 41 | i.src = base + "button?title=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(url); 42 | i.scrolling = "auto"; 43 | i.frameBorder = "0"; 44 | i.width = "75px"; 45 | i.height = "20px"; 46 | i.className = "hn-share-iframe"; 47 | 48 | anchor.parentNode.insertBefore(i, anchor); 49 | anchor.parentNode.removeChild(anchor); 50 | } 51 | })(window); -------------------------------------------------------------------------------- /hnbutton/button.html: -------------------------------------------------------------------------------- 1 | {{define "button"}} 2 | 3 | 4 | 5 |
6 | 16 | 17 | 18 |
53 |