Home > Web Front-end > JS Tutorial > How to set up geasemonkey automatic login script

How to set up geasemonkey automatic login script

一个新手
Release: 2017-09-19 11:06:19
Original
1231 people have browsed it

// ==UserScript==
// @name        自动填写用户名和密码
// @namespace   AutoLogin
// @version     1
// @include     https://XXX.XXX.XXX.XXX/login/requireLogin
// @include     https://XXX.XXX.XXX.XXX/login/requireLogin
// @include     https://XXX.XXX.XXX.XXX/accounts/login*
// @grant       none
// ==/UserScript==

var globalConfig = {
    'siteList': [
            {
                targetUrlRegex : new RegExp("^https:\/\/XXX.XXX.XXX.XXX\/login\/requireLogin$"),  
                attributeName: 'id',
                usernameKey: 'username',
                usernameVal: '****',
                passwordKey: 'password',
                passwordVal: '****',
            },
           {
                targetUrlRegex : new RegExp("^https:\/\/XXX.XXX.XXX.XXX\/accounts\/login.*\/$"),   
                attributeName: 'id',
                usernameKey: 'username',
                usernameVal: '****',
                passwordKey: 'password',
                passwordVal: '****',
            },
            {
                targetUrlRegex : new RegExp("^https:\/\/XXX.XXX.XXX.XXX\/(index\.php)?$"), 
                attributeName: 'id',
                usernameKey: 'UserName',
                usernameVal: '****',
                passwordKey: 'UserPasswd',
                passwordVal: '****',
            },
            {
                targetUrlRegex : new RegExp("^https:\/\/XXX.XXX.XXX.XXX\/SignIn.screen$"), 
                attributeName: 'id',
                usernameKey: 'username',
                usernameVal: '****',
                passwordKey: 'password',
                passwordVal: '****',
            },
        ]
};

window.autologin = function() {
    var sitelist = globalConfig.siteList;
        if (!sitelist.length) {
            return;
        }
     //;
    var cur_url = window.location;
     //;
    for (var indx in sitelist) {
            var test = sitelist[indx].targetUrlRegex.test(cur_url);
            if (!test) {
               continue;
            }
            var inputs = document.body.getElementsByTagName('input');
//
            for (var i in inputs) {
                var input = inputs[i];
                if (input[sitelist[indx].attributeName] == sitelist[indx].usernameKey) {
                    input.value = sitelist[indx].usernameVal;
                } else if (input[sitelist[indx].attributeName] == sitelist[indx].passwordKey) {
                    input.value = sitelist[indx].passwordVal;
                } 
            }
            document.getElementsByTagName("form")[0].submit();  
    }
}

window.setTimeout("autologin()",1000);
Copy after login

    The above is the detailed content of How to set up geasemonkey automatic login script. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template