Last active
December 21, 2018 17:12
-
-
Save henrik/f7d25092582f64bf15925671692e8f49 to your computer and use it in GitHub Desktop.
Automatically fills out characters from your "memorable information" on TSB. For use with https://tampermonkey.net/ in e.g. Chrome.
This file contains hidden or 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 TSB Memorable Information Autofill | |
// @namespace http://henrik.nyh.se/ | |
// @version 0.1 | |
// @description Automatically fills out characters from your "memorable information". Prompts for the full string the first time only. Intentionally fills out but doesn't submit, so you're in control. | |
// @author Henrik Nyh | |
// @match https://internetbanking.tsb.co.uk/personal/logon/login/ | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @updateURL https://gist.githubusercontent.com/henrik/f7d25092582f64bf15925671692e8f49/raw | |
// ==/UserScript== | |
(function() { | |
"use strict"; | |
// The page loads on the "#/login" page, then "navigates" to "#/memorableInformation". | |
window.addEventListener("hashchange", function() { | |
if (location.hash !== "#/memorableInformation") return; | |
var memorableInformation = GM_getValue("memi"); | |
if (!memorableInformation) { | |
memorableInformation = prompt("Please enter your memorable information. It will only be stored locally on your machine."); | |
GM_setValue("memi", memorableInformation); | |
} | |
if (!memorableInformation) return; | |
var retryInterval = setInterval(function() { | |
var positions = document.getElementById("page").innerText.match(/enter characters (\d+), (\d+) and.(\d+)/); | |
if (positions) { | |
clearInterval(retryInterval); | |
} else { | |
return; // Try again in a while. | |
} | |
var positionA = parseInt(positions[1]); | |
var positionB = parseInt(positions[2]); | |
var positionC = parseInt(positions[3]); | |
var dropdownA = document.getElementById("charXPos"); | |
var dropdownB = document.getElementById("charYPos"); | |
var dropdownC = document.getElementById("charZPos"); | |
dropdownA.value = memorableInformation[positionA - 1]; | |
dropdownB.value = memorableInformation[positionB - 1]; | |
dropdownC.value = memorableInformation[positionC - 1]; | |
// Seems we also need to trigger an event for Angular to notice these fields changed. | |
var e = document.createEvent("HTMLEvents"); | |
e.initEvent("change", false, true); | |
dropdownA.dispatchEvent(e); | |
dropdownB.dispatchEvent(e); | |
dropdownC.dispatchEvent(e); | |
}, 100); | |
}, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment