Created
December 21, 2009 15:34
-
-
Save jtrim/260998 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 jQuery + printforms | |
// @namespace jQuery | |
// @description Use jQuery to print form variables and input element values on submit - cancels form submit | |
// @author Joan Piedra (jQuery integration) + Jesse Trimble | |
// @homepage http://www.joanpiedra.com/jquery/greasemonkey - http://www.rmrdevelopment.com | |
// @include * | |
// ==/UserScript== | |
// Add jQuery | |
var GM_JQ = document.createElement('script'); | |
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js'; | |
GM_JQ.type = 'text/javascript'; | |
document.getElementsByTagName('head')[0].appendChild(GM_JQ); | |
// Check if jQuery's loaded | |
function GM_wait() { | |
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); } | |
else { $ = unsafeWindow.jQuery; letsJQuery(); } | |
} | |
GM_wait(); | |
// All your GM code must be inside this function | |
function letsJQuery() | |
{ | |
var bg_colors = ['black', 'blue', 'cyan', 'green', '#5b0000', 'yellow', 'magenta']; | |
var txt_colors = ['white', 'white', 'green', 'white', 'white', 'blue', 'yellow']; | |
var i; | |
$('form').each(function(index) | |
{ | |
i = index; | |
var elem = $('<div></div>').css({ | |
backgroundColor: bg_colors[i], | |
color: txt_colors[i], | |
fontSize: '9pt' | |
}); | |
elem.append($('form:eq(0)').serialize()); | |
$(this).submit(function() | |
{ | |
$('html div:eq(0)').before(elem); | |
return false; | |
}); | |
}); | |
$('input[type=submit]').add('input[type=button]').each(function(i) | |
{ | |
var elem2 = $('<div class="inputvals"></div>').css({ | |
backgroundColor: 'green', | |
color: 'white', | |
fontSize: '9pt' | |
}); | |
$('input').add('textarea').each(function() | |
{ | |
elem2.append('<div>' + this.name + ' : ' + this.value + '</div>'); | |
}); | |
$(this).click(function() | |
{ | |
$('.inputvalues').remove(); | |
$('html div:eq(0)').before(elem2); | |
return false; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment