Last active
April 21, 2016 18:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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