GitHub images as icons

Show images in Github repositories source tree as 16x16 icons

Stan na 24-10-2014. Zobacz najnowsza wersja.

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 images as icons
// @description Show images in Github repositories source tree as 16x16 icons
// @namespace   wOxxOm.scripts
// @include     https://github.com/*
// @match       https://github.com/*
// @version     1
// @grant       none
// @run-at      document-start
// ==/UserScript==

function iconify(n) {
  var aa = (n.className == 'js-directory-link') ? [n] : n.getElementsByClassName('js-directory-link');
  for (var a, i=0; i<aa.length && (a=aa[i++]); ) {
    var r = a.href.match(/github\.com\/(.+?\/)blob\/([^\/]+\/.+?\.(?:png|jpg|jpeg|bmp|gif|cur|ico))$/);
    if (!r)
      continue;

    var td = a.parentNode.parentNode;
    if (td.localName != 'td')
      continue;
    td = td.previousElementSibling;

    var icon = td.firstElementChild;
    var img = document.createElement('img');
    td.insertBefore(img, icon);
    td.removeChild(icon);

    img.style.maxWidth = img.style.maxHeight = '16px';
    img.src = 'https://raw.githubusercontent.com/' + r[1] + r[2];
  }
}

if (document.body)
  iconify(document.body);

var ob = new MutationObserver(function(mutations){
  for (var m, i=0; i<mutations.length && (m=mutations[i++]); )
    if (m.target.id == 'js-repo-pjax-container' || (m.target.className == 'files' && m.target.localName == 'table'))
      for (var nn=m.addedNodes, n, j=0; j<nn.length && (n=nn[j++]); )
        if (n.nodeType == Node.ELEMENT_NODE)
            iconify(n);
});
ob.observe(document, {subtree:true, childList:true});