github-npm-deps

Link dependencies from package.json to respective GitHub homepages

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
}