github-npm-deps

Link dependencies from package.json to respective GitHub homepages

  1. // ==UserScript==
  2. // @name github-npm-deps
  3. // @version 0.1.0
  4. // @description Link dependencies from package.json to respective GitHub homepages
  5. // @license MIT
  6. // @namespace https://github.com/eush77/github-npm-deps
  7. // @supportURL https://github.com/eush77/github-npm-deps
  8. // @include https://github.com/*
  9. // ==/UserScript==
  10.  
  11.  
  12. init();
  13. document.addEventListener('click', function () {
  14. setTimeout(init, 500);
  15. });
  16.  
  17.  
  18. function init () {
  19. if (!/\/package\.json$/.test(location.pathname)) {
  20. return;
  21. }
  22.  
  23. var trs = document.querySelectorAll('.blob-wrapper tr');
  24.  
  25. [].reduce.call(trs, function (inDependencies, tr) {
  26. var row = tr.querySelector('.blob-code');
  27. if (row.textContent.indexOf('}') >= 0) {
  28. return false;
  29. }
  30.  
  31. var pls = row.querySelectorAll('.pl-s');
  32.  
  33. if (pls.length == 1) {
  34. pls = pls[0];
  35. if (pls.nextSibling &&
  36. pls.nextSibling.textContent.replace(/\s/g, '') == ':{' &&
  37. /^"\w*[dD]ependencies"$/.test(pls.textContent)) {
  38. return true;
  39. }
  40. }
  41. else if (inDependencies && pls.length == 2) {
  42. var name = pls[0].textContent;
  43. var link = document.createElement('a');
  44. link.href = 'http://ghub.io/' + name.slice(1, -1);
  45. link.textContent = name;
  46. pls[0].parentNode.replaceChild(link, pls[0]);
  47. }
  48.  
  49. return inDependencies;
  50. }, false);
  51. }