Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Forked from adonaldson/INSTALLATION
Created February 27, 2010 18:54
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 chrisroos/316880 to your computer and use it in GitHub Desktop.
Save chrisroos/316880 to your computer and use it in GitHub Desktop.
HSBC login bookmarklet
var hsbc_config = {};
hsbc_config.ibu = 'IB1234567890';
hsbc_config.dob = 'DDMMYY';
hsbc_config.sec = '123456';
if (document.getElementById('intbankingID')) {
document.getElementById('intbankingID').value = hsbc_config.ibu;
var submit_command = unescape(document.getElementById('IBlogon').parentNode.href).replace(/javascript: /, '');
eval(submit_command);
} else if (document.getElementById('password')) {
var numbers = document.getElementById('password').parentNode.getElementsByTagName('span');
var codes = [];
for(var ii=0; ii<numbers.length; ii++) {
var position = numbers[ii].children[0].innerHTML;
var idx = undefined;
switch(position) {
case 'FIRST': idx = 0; break;
case 'SECOND': idx = 1; break;
case 'THIRD': idx = 2; break;
case 'FOURTH': idx = 3; break;
case 'NEXT TO LAST': idx = 4; break;
case 'LAST': idx = 5; break;
}
codes.push(hsbc_config.sec[idx]);
}
if (codes.length == 3)
document.getElementById('password').value = codes.join('');
var dob_label = document.getElementsByTagName('label')[0];
document.getElementById(dob_label.htmlFor).value = hsbc_config.dob;
document.getElementById('userPrefs').parentNode.submit();
} else {
location.href = 'https://www.hsbc.co.uk/1/2/HSBCINTEGRATION/CAM10';
};
// Please see http://dies-el.co.uk/hsbc_bookmarklet for more information
//
// Before running, enter your details into the variables at the top of the source code. This file is commented show
// my intentions. Please use hsbc_login_bookmarklet.js with the bookmarklet builder above.
var hsbc_config = {};
hsbc_config.ibu = ''; // Your IB number, including the 'IB' part
hsbc_config.dob = ''; // Your date of birth, DDMMYY
hsbc_config.sec = ''; // Your six digit security code
// If this element exists, we must be on the login form. Right? RIGHT?
if (document.getElementById('intbankingID')) {
document.getElementById('intbankingID').value = hsbc_config.ibu;
// Find the submit button... image, jump to it's parent (an A tag), take its href and replace the
// 'javascript:' protocol. Then Eval! We don't need no steenking submits.
var submit_command = unescape(document.getElementById('IBlogon').parentNode.href).replace(/javascript: /, '');
eval(submit_command);
} else if (document.getElementById('password')) {
// Otherwise, hell, we're undoubtedly on the second page of the login form!
// Find the random position strings (e.g. FIRST, THIRD, FOURTH) based on the markup. Extract.
var numbers = document.getElementById('password').parentNode.getElementsByTagName('span');
var codes = [];
for(var ii=0; ii<numbers.length; ii++) {
var position = numbers[ii].children[0].innerHTML;
var idx = undefined;
switch(position) {
case 'FIRST': idx = 0; break;
case 'SECOND': idx = 1; break;
case 'THIRD': idx = 2; break;
case 'FOURTH': idx = 3; break;
case 'NEXT TO LAST': idx = 4; break;
case 'LAST': idx = 5; break;
}
// Push the correct value from your secret number onto our codes array.
codes.push(hsbc_config.sec[idx]);
}
// Fancy-Dan error checking. Enter the password assuming it seems correct
if (codes.length == 3)
document.getElementById('password').value = codes.join('');
// Winner of 'point-where-explosions-are-most-likely-to-happen'
// Tweaked because HSBC changed the markup. Rather than hardcoding the ID of the element, we'll
// assume (eugh) that the dob field is associated with the first label on the page. Bulletproof!
var dob_label = document.getElementsByTagName('label')[0];
document.getElementById(dob_label.htmlFor).value = hsbc_config.dob;
// Find the form, submit it. We don't need no steenking images wrapped by links with eval'd javascript.
document.getElementById('userPrefs').parentNode.submit();
} else {
// To the login page!
location.href = 'https://www.hsbc.co.uk/1/2/HSBCINTEGRATION/CAM10';
};
These are the steps I took to get the HSBC Bookmarklet (http://dies-el.co.uk/hsbc_bookmarklet) installed.
1. Get a copy of John Gruber's perl script to create bookmarklets (I've copied it and created a gist)
$ git clone git://gist.github.com/316867.git make-bookmarklet
2. Get a copy of Andrew Donaldson's HSBC auto logger inner
$ git clone git://gist.github.com/266260.git hsbc-bookmarklet
3. Add your hsbc credentials to hsbc-bookmarklet/hsbc_bookmarklet.js
4. Bookmarkify the javascript
$ cat hsbc-bookmarklet/hsbc_bookmarklet.js | perl make-bookmarklet/make-bookmarklet.pl
5. Create a html page with a link to the bookmarklet
$ ruby -e 'puts "<a href=\"#{`pbpaste`}\">HSBC Login</a>"' > bookmarklet.html
6. Open the html page and drag it to your bookmarks bar
$ open bookmarklet.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment