GitHub images as icons

Show images in Github repositories source tree as 16x16 icons

24.10.2014 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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.01
// @grant       GM_addStyle
// @run-at      document-start
// ==/UserScript==

function addStyle(e) {
  GM_addStyle('.wOxxOm-image-icon { max-width:16px; max-height:16px; width:auto; height:auto; margin-left:-2px }')
  window.removeEventListener('DOMContentLoaded', addStyle);
  iconify(document.body);
}
window.addEventListener('DOMContentLoaded', addStyle);

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.previousElementSibling;
    if (td.localName != 'td')
      continue;
    
    var icon = td.firstElementChild;
    var img = icon.nextElementSibling;
    if (!img)
      td.insertBefore(img = document.createElement('img'), icon);
    
    icon.style.display = 'none';
    img.className = 'wOxxOm-image-icon';
    img.src = 'https://raw.githubusercontent.com/' + r[1] + r[2];
  }
}

var ob = new MutationObserver(function(mutations){
  for (var m, i=0; i<mutations.length && (m=mutations[i++]) && (mtg=m.target); )
    if (mtg.id == 'js-repo-pjax-container' || (mtg.className == 'files' && mtg.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});