Skip to content

Instantly share code, notes, and snippets.

@Grazfather
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grazfather/aa1da6d9a33fad4eb3d2 to your computer and use it in GitHub Desktop.
Save Grazfather/aa1da6d9a33fad4eb3d2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name RabbitMQ Purge Button Adder
// @namespace http://www.grazfather.com/userscripts/purgeButton.user.js
// @version 0.1
// @description Adds a 'purge' button to every queue in queues view.
// @match http://localhost:15672/*
// @copyright Me
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function purge_button_main() {
var original_partial_update; // Holds the original partial_update function
function add_purge_buttons() {
debugger;
jQ('#main div.updatable').children('table').children('tbody').children('tr').each(function (index) {
var queuename = jQ(this).children('td').children('a').html();
jQ(this).append('<td class="r"><form action="#/queues" method="delete" class="inline-form-right">' +
'<input type="hidden" name="vhost" value="/">' +
'<input type="hidden" name="name" value="' + queuename + '">' +
'<input type="hidden" name="mode" value="purge">' +
'<input type="submit" value="Purge">' +
'</form></td>');
});
}
function new_partial_update() {
console.log("In new partial_update()");
add_purge_buttons();
// Call original...
original_partial_update();
// ... and add our buttons
}
console.log("In purge button main");
jQ(document).ready(function () {
add_purge_buttons();
// Hook the partial update function
console.log("Hooking partial_update");
//debugger;
original_partial_update = partial_update;
partial_update = new_partial_update;
});
}
// load jQuery and execute the main function
console.log("Loading JQuery and calling purge_button_main");
addJQuery(purge_button_main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment