Skip to content

Instantly share code, notes, and snippets.

@curtisharvey
Last active April 21, 2016 18:00
Show Gist options
  • Save curtisharvey/6f95deac90fbd2ccdfcf to your computer and use it in GitHub Desktop.
Save curtisharvey/6f95deac90fbd2ccdfcf to your computer and use it in GitHub Desktop.
Ugly hack to add "Source" and "Target" columns to Bitbucket Pull Requests list
/*jslint browser:true*/
// ==UserScript==
// @name Bitbucket PR branches
// @namespace http://curtisharvey.com/
// @version 0.1
// @description Ugly hack to add "Source" and "Target" columns to Bitbucket Pull Requests list
// @author Curtis Harvey
// @match https://bitbucket.org/*/pull-requests/
// @match https://bitbucket.org/*/pull-requests/?displaystatus=open
// ==/UserScript==
(function () {
'use strict';
var prTable = document.querySelector('#list-pullrequests table'),
prRows = Array.prototype.slice.call(prTable.querySelectorAll('tr')),
prDoc = document.implementation.createHTMLDocument('pr');
prRows.forEach(function (row) {
var source, target, insertPoint, req;
if (row.parentNode.tagName === 'THEAD') {
insertPoint = row.querySelector('th:nth-of-type(3)');
source = document.createElement('th');
target = document.createElement('th');
source.innerHTML = 'Source';
target.innerHTML = 'Target';
source.style.width = '20%';
target.style.width = '15%';
// insert
row.insertBefore(source, insertPoint);
row.insertBefore(target, insertPoint);
} else {
insertPoint = row.querySelector('td:nth-of-type(3)');
source = document.createElement('td');
target = document.createElement('td');
source.className = 'source-branch';
target.className = 'target-branch';
// insert
row.insertBefore(source, insertPoint);
row.insertBefore(target, insertPoint);
// fetch branch details
req = new XMLHttpRequest();
req.addEventListener('load', function () {
if (this.status === 200) {
prDoc.documentElement.innerHTML = this.responseText;
var branches = prDoc.querySelectorAll('dd.branch a[title]');
row.querySelector('.source-branch').appendChild(branches[0]);
row.querySelector('.target-branch').appendChild(branches[1]);
}
});
req.open('get', row.querySelector('td.title a').href, true);
req.send();
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment