<commit_before>// ==UserScript==
// @name	Crédit Agricole login autofill
// @namespace	memmie.lenglet.name
// @author	mems <<EMAIL>>
// @homepageURL https://github.com/mems/ca-login-autofill/
// @description	Enable password autofill on Crédit Agricole.
// @include	https://www.*-enligne.credit-agricole.fr/stb/entreeBam
// @license	MIT
// @updateURL   https://openuserjs.org/meta/mems/Cr%C3%A9dit_Agricole_login_autofill.meta.js
// @downloadURL https://openuserjs.org/src/scripts/mems/Cr%C3%A9dit_Agricole_login_autofill.user.js
// @version	1.0.1
// @grant	none
// ==/UserScript==

// Create a map from button to index
var keymap = Array.from(document.querySelectorAll("#pave-saisie-code a")).reduce((map, anchor) => {let val = anchor.textContent.trim(); val !== "" && map.set(val, anchor.parentElement); return map }, new Map())
var backspace = Array.from(document.getElementsByTagName("a")).find(anchor => anchor.textContent.trim() == "Corriger");
var input = document.createElement("input");
input.type = "password";
input.style = "position: fixed; right: 100%; bottom: 100%; opacity: 0;"
input.addEventListener("input", function(event){
	while(backspace && document.formulaire.CCCRYC2.value.length > 0){
		//backspace.dispatchEvent(new MouseEvent("click"));// but since href="javascript:..." is executed async, this cause an infinite loop here
		eval(backspace.href)// it's sync
	}
	for(let char of this.value){
		keymap.has(char) && keymap.get(char).dispatchEvent(new MouseEvent("click"));
	}
})
var account = document.querySelector("input[name=CCPTE]");
account.parentElement.insertBefore(input, account.nextSibling);<commit_msg>Rewrite pre-2020 script<commit_after>// ==UserScript==
// @name	Crédit Agricole login autofill
// @namespace	memmie.lenglet.name
// @author	mems <<EMAIL>>
// @homepageURL https://github.com/mems/ca-login-autofill/
// @description	Enable password autofill on Crédit Agricole.
// @include	https://www.*-enligne.credit-agricole.fr/stb/entreeBam
// @include	https://www.credit-agricole.fr/*/*/acceder-a-mes-comptes.html
// @license	MIT
// @updateURL   https://openuserjs.org/meta/mems/Cr%C3%A9dit_Agricole_login_autofill.meta.js
// @downloadURL https://openuserjs.org/src/scripts/mems/Cr%C3%A9dit_Agricole_login_autofill.user.js
// @version	1.0.2
// @grant	none
// ==/UserScript==

// Create a map from button to index
const keymap = [...document.querySelectorAll("#pave-saisie-code a")].reduce((map, anchor) => {
	const val = anchor.textContent.trim();
	return val !== "" ? map.set(val, anchor.parentElement) : map;
}, new Map());
const backspace = [...document.getElementsByTagName("a")].find(anchor => anchor.textContent.trim() == "Corriger");
const backspaceExec = (function(){with(this){eval(backspace.href)}}).bind(unsafeWindow);// use page context, not sandbow context

// Fake password input that let password manager fill it and trigger pad
const input = document.createElement("input");
input.type = "password";
input.autocomplete = "current-password";
input.style = "position: fixed; right: 100%; bottom: 100%; opacity: 0;"
input.addEventListener("input", function(event){
	// Clear current value
	while(backspace && document.formulaire.CCCRYC2.value.length > 0){
		// backspace.dispatchEvent(new MouseEvent("click"));
		// but because href="javascript:..." is executed async, this cause an infinite loop here
    try{
			backspaceExec();
    }
    catch(error){}
	}
	
	for(const char of this.value){
		if(!keymap.has(char)){
			continue;
		}
		keymap.get(char).dispatchEvent(new MouseEvent("click"));
	}
});

const account = document.querySelector("input[name=CCPTE]");
account.parentElement.insertBefore(input, account.nextSibling);

// Allow to remove the last char
backspace.addEventListener("click", event => {
	input.value = input.value.slice(0, -1);
});
{'fraction_non_alphanumeric': 0.1701735928458706, 'fraction_numerical': 0.009994739610731194, 'mean_word_length': 4.868827160493828, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 9, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5416400', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1264, 'n_words': 259}