github-npm-deps

Link dependencies from package.json to respective GitHub homepages

Verze ze dne 10. 08. 2015. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         github-npm-deps
// @version      0.1.0
// @description  Link dependencies from package.json to respective GitHub homepages
// @license      MIT
// @namespace    https://github.com/eush77/github-npm-deps
// @supportURL   https://github.com/eush77/github-npm-deps
// @include      https://github.com/*
// ==/UserScript==


init();
document.addEventListener('click', function () {
  setTimeout(init, 500);
});


function init () {
  if (!/\/package\.json$/.test(location.pathname)) {
    return;
  }

  var trs = document.querySelectorAll('.blob-wrapper tr');

  [].reduce.call(trs, function (inDependencies, tr) {
    var row = tr.querySelector('.blob-code');
    if (row.textContent.indexOf('}') >= 0) {
      return false;
    }

    var pls = row.querySelectorAll('.pl-s');

    if (pls.length == 1) {
      pls = pls[0];
      if (pls.nextSibling &&
          pls.nextSibling.textContent.replace(/\s/g, '') == ':{' &&
          /^"\w*[dD]ependencies"$/.test(pls.textContent)) {
        return true;
      }
    }
    else if (inDependencies && pls.length == 2) {
      var name = pls[0].textContent;
      var link = document.createElement('a');
      link.href = 'http://ghub.io/' + name.slice(1, -1);
      link.textContent = name;
      pls[0].parentNode.replaceChild(link, pls[0]);
    }

    return inDependencies;
  }, false);
}