Created
April 18, 2015 09:04
-
-
Save squio/2508512a2dbe05c9c4bc to your computer and use it in GitHub Desktop.
Greasmonkey script (Firefox) - download de laatste N afschriften van Triodos.nl
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 Triodos afschriften downloader | |
// @namespace http://squio.nl/triodos | |
// @include https://bankieren.triodos.nl/ib-seam/pages/accountinformation/statement/statementoverview.seam | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// NEVER execute any code into a banking site if you're not absolutely certain it is safe!!! | |
// Make sure you fully UNDERSTAND what this is doing before proceeding. | |
var statementId = "main:statTable:%d:printStatementLink"; // 0 based index | |
var inputForm = document.createElement("DIV"); | |
inputForm.innerHTML = "Download laatste afschriften, aantal:<br><input type='text' id='gm_stmt_itemcount' value='0'><br><button id='gm_stmt_downloader'>Download</button>"; | |
document.querySelector("#messagesDiv").appendChild(inputForm); | |
document.querySelector("#gm_stmt_downloader").addEventListener("click", function() { | |
var total = parseInt(document.querySelector("#gm_stmt_itemcount").value, 10); | |
if (total >= 1) { | |
--total; | |
} else { | |
alert("Download minimaal 1 afschrift (" + total + ")"); | |
return; | |
} | |
var delay = 1; | |
for (var i=total; i>=0; i--) { | |
setTimeout(getClicker(i), delay); | |
delay += 4000; | |
} | |
}); | |
function getClicker(id) { | |
return function() { | |
var eltId = statementId.replace(/%d/, id); | |
simulateClick(eltId); | |
}; | |
} | |
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent | |
function simulateClick(eltId) { | |
var evt = new MouseEvent("click", { | |
bubbles: true, | |
cancelable: true, | |
view: window, | |
}); | |
var cb = document.getElementById(eltId); //element to click on | |
var canceled = !cb.dispatchEvent(evt); | |
cb.style.border = "1px solid magenta"; | |
// document.querySelector("#gm_stmt_itemcount").value = eltId; | |
if(canceled) { | |
// A handler called preventDefault | |
console.log("canceled click #" + eltId); | |
} else { | |
// None of the handlers called preventDefault | |
console.log("processed click #" + eltId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment