emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add a commit hash (first 6 chars) column to cgit webpage?


From: Yuri Khan
Subject: Re: Add a commit hash (first 6 chars) column to cgit webpage?
Date: Thu, 5 May 2016 18:15:04 +0600

On Wed, May 4, 2016 at 9:16 PM, Kaushal Modi <address@hidden> wrote:
>> Which browser do you use? I could probably whip something up in
>> Greasemonkey (which is a Firefox extension). I am also told
>> Greasemonkey scripts can be installed in Chrom{e,ium}.
>
> Thanks! I use both Firefox (on RHEL) and Chrome (on Windows).

I have hosted the script on my home server:

http://greasemonkey.centaur.ath.cx/cgit_Add_commit_hash_column.user.js

You can install this in Firefoxoids using the Greasemonkey or
Tampermonkey extension, and in Chromides using Tampermonkey.

If you need this on other aliases of Savannah cgit, or on other cgit
instances, just add the corresponding @include patterns. (If you feel
adventurous, replace the host with a *; this will enable the script on
all pages whose URL contains /cgit/ and /log/ in that order.)

The script makes some assumptions about the page DOM structure and is
therefore subject to software rot if that structure changes.

(Security notice: Userscripts run in the security context of your
browser. Carefully review any userscript you install.)

A courtesy inspection/archival copy follows.

// ==UserScript==
// @name        cgit: Add commit hash column
// @namespace   http://yurikhan.github.io/
// @include     http://git.savannah.gnu.org/cgit/*/log/*
// @version     1
// @grant       none
// ==/UserScript==

var header_row = document.querySelector('table.list tr:first-child');
var th = document.createElement('th');
th.className = 'left';
th.textContent = 'Hash';
var before = header_row.querySelector('th:nth-child(2)');
header_row.insertBefore(th, before);

var rows = document.querySelectorAll('table.list tr:not(.nohover)');
Array.prototype.forEach.call(rows, function(row) {
  var link = row.querySelector('a[href*="/commit/"]');
  var hash = null;
  ((link.search || '').replace(/^\?/, '').split('&')
   .map(function(param) { return param.split('='); })
   .filter(function(pair) { return pair[0] === 'id'; })
   .forEach(function(pair) { hash = pair[1]; }))
  var td = document.createElement('td');
  td.textContent = (hash || '').slice(0, 7);
  for (var before = link;
       !(before instanceof HTMLTableCellElement);
       before = before.parentNode);
  row.insertBefore(td, before);
});

rows = document.querySelectorAll(
  'table.list tr.nohover:not(:first-child)');
Array.prototype.forEach.call(rows, function(row) {
  var td = document.createElement('td');
  var before = row.querySelector('td:nth-child(2)');
  row.insertBefore(td, before);
});



reply via email to

[Prev in Thread] Current Thread [Next in Thread]