CaixaDirecta Sem Teclado Virtual

Enables using the keyboard on the login screen of the Portuguese Caixadirecta on-line homebanking service, rather than being restricted to the virtual on-screen keyboard.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           CaixaDirecta Sem Teclado Virtual
// @namespace      https://greasyfork.org/users/3063-miguel-p
// @include        https://caixadirectaonline.cgd.pt/cdo/*
// @description Enables using the keyboard on the login screen of the Portuguese Caixadirecta on-line homebanking service, rather than being restricted to the virtual on-screen keyboard.
// @version 0.0.1.20140626142038
// ==/UserScript==

(function () {
    function injectScript(scriptToInject) {
        var script = document.createElement('script'); 
        script.type = "text/javascript"; 
        script.innerHTML = scriptToInject;
        document.getElementsByTagName('head')[0].appendChild(script);
    }
    
    // this does things to the login page
    var userInput = document.getElementById('userInput');
    if(userInput) {
        // no keyboard hijacking, thanks
        document.onkeypress = null;
        
        // remove readonly attributes from input fields
        userInput.removeAttribute('readonly');
        var passwordInput = document.getElementById('passwordInput');
        passwordInput.removeAttribute('readonly');
        
        // virtual keyboard now stores the password itself in a global var, the password field is just a dummy
        // we need to copy the data from the dummy field into the global var before the site's form handler runs
        // (the site's handler performs the login via an ajax request)
        
        // login form has a submit handler, defined through an old version of JQuery. It's an anonymous function, nab a reference to it
        // might as well wipe it out through jquery too, since we already got our hands dirty with it
        injectScript("oldSubmitCallback = jQuery(loginForm).data('events').submit[0].handler; jQuery(loginForm).unbind('submit');");

        // Replace with our better callback that sets the global var to the proper password
        var newCallback = function newCallback(evt) {
            var realPassword = document.getElementById('loginForm').elements['passwordInput'].value;
            
            // check if the user actually used the virtual keyboard, don't overwrite the password with asterisks
            if(realPassword.indexOf("*") > -1) {
                injectScript("oldSubmitCallback();");
            } else {
                injectScript("login_password = '" + realPassword + "'; oldSubmitCallback();");
            }
        }
        document.getElementById('loginForm').addEventListener('submit', newCallback);

        // clear out login popup
        el = document.getElementById('modal_shadow_zero');
        el.parentNode.removeChild(el);
        el = document.getElementById('zeroHPModalPanel');
        el.parentNode.removeChild(el);
        userInput.focus();
    }
    
    // this does things to the post-login page
    var popupLogin = document.getElementById('modal_shadow_pzero');
    if(popupLogin) {
        // clear out the post-login popup
        el = document.getElementById('zeroHPModalPanel2');
        el.parentNode.removeChild(el);
        el = document.getElementById('modal_shadow_pzero');
        el.parentNode.removeChild(el);
    }
})();