Skip to content

Instantly share code, notes, and snippets.

@aasmith
Created May 23, 2011 16:24
Show Gist options
  • Save aasmith/986986 to your computer and use it in GitHub Desktop.
Save aasmith/986986 to your computer and use it in GitHub Desktop.
Capture OFX for USBank
// inject jquery
var head = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
newScript.onload = function() { head.removeChild(newScript); modifyDom() };
head.appendChild(newScript);
// method that serializes the current form, and AJAX posts to the same place as the original form
var ajaxPost = function() {
console.log("AJAX POSTing...");
var form = jQuery(document.download)
var url = form.attr('action');
var data = form.serialize();
jQuery.post(url, data, ofxHandler, "text");
}
// if the page is unloaded before downloading warn the user.
window.onunload = function() { alert('page unloaded: reapply the bookmarklet!') }
// callback that reads the server response from the post. this should contain the ofx data.
var ofxHandler = function(ofx) {
console.log("GOT OFX RESPONSE");
console.log(ofx);
}
var modifyDom = function() {
// hook onto submit link
// $("form[name=download] img[src*='download']").parent().attr('onclick', 'ajaxPost(); checkInput(document.download); return false;');
jQuery("form[name=download] img[src*='download']").parent().attr('onclick', '(function(){document.download.submit=function(){};checkInput(document.download)})(); ajaxPost(); return false;');
}
// now use the form, and click download.
// ofx data should appear on the console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment