Hacker News

Add a link in the top banner of [Hacker News discussion](http://news.ycombinator.com/) to its counter part at [HN Premii](http://hn.premii.com/)

  1. // ==UserScript==
  2. // @name Hacker News
  3. // @namespace com.ycombinator.news
  4. // @include https://news.ycombinator.com/*
  5. // @version 2.0
  6. // @grant none
  7. // @description Add a link in the top banner of [Hacker News discussion](http://news.ycombinator.com/) to its counter part at [HN Premii](http://hn.premii.com/)
  8. // ==/UserScript==
  9.  
  10. function getParameterByName(name, url) {
  11. if (!url) url = window.location.href;
  12. name = name.replace(/[\[\]]/g, "\\$&");
  13. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  14. results = regex.exec(url);
  15. if (!results) return null;
  16. if (!results[2]) return '';
  17. return decodeURIComponent(results[2].replace(/\+/g, " "));
  18. }
  19.  
  20. function readerUrl(id)
  21. {
  22. var url = 'http://hn.premii.com/';
  23. if (id !== null && id.length > 0)
  24. {
  25. url += '#/comments/' + id;
  26. }
  27. return url;
  28. }
  29.  
  30.  
  31. var id = getParameterByName("id", window.location.href);
  32. var readerLink = ' | <a href="' + readerUrl(id) + '">Reader</a>';
  33. var topMenu = document.getElementsByClassName('pagetop') [0];
  34. topMenu.innerHTML += readerLink;
  35.  
  36.