-
-
Save javawizard/86a461fce26171eace60 to your computer and use it in GitHub Desktop.
This file contains 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
// ==UserScript== | |
// @name Firework Links | |
// @namespace http://joelhough.com/ | |
// @version 0.1 | |
// @description add firework links to gerrit | |
// @match https://gerrit.instructure.com/* | |
// @copyright 2014+, Joel Hough | |
// ==/UserScript== | |
function add_links() { | |
var change_num_match = window.location.toString().match(/c\/(\d+)/); | |
if (change_num_match) { | |
var change_num = change_num_match[1]; | |
// Old screen | |
var els = document.querySelectorAll('table.gwt-DisclosurePanel td'); | |
var links_added = false; | |
for (var i = 0; i < els.length; i++) { | |
var e = els[i]; | |
var match = e.innerHTML.match(/^\w*Patch Set (\d+)\w*$/); | |
if (match && !e.className.match(/fireworked/)) { | |
e.className += ' fireworked'; | |
links_added = true; | |
var patch_num = match[1]; | |
var firework_link = 'http://firework.instructure.com/runs/gerrit/' + change_num + '/' + patch_num; | |
var a = document.createElement('a'); | |
a.href = firework_link; | |
a.className = 'gwt-Anchor patchSetLink'; | |
a.appendChild(document.createTextNode('(firework)')); | |
e.parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling.appendChild(a); // Don't judge me | |
} | |
} | |
// New screen | |
var patch = window.location.href.match(/c\/\d+(\/\d+)?/); | |
if (patch) { | |
var patch_num = patch[1] || ''; | |
var td = $('th').filter(function() {return $(this).text() == "Commit"}).parent().find('td:has(a)'); | |
if (td.length) { | |
var existing = td.find('span[data-patch]'); | |
if (existing.length === 0 || existing.data('patch') != patch_num) { | |
existing.remove(); | |
td.append('<span data-patch="' + patch_num + '"> <a href="http://firework.instructure.com/runs/gerrit/' + change_num + patch_num + '">(firework)</a></span>'); | |
} | |
} | |
} | |
} | |
setTimeout(add_links, 1000); | |
} | |
setTimeout(add_links, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment