欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

geasemonkey自动登陆脚本如何设置

程序员文章站 2022-04-24 15:14:27
...
// ==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);

    以上就是geasemonkey自动登陆脚本如何设置的详细内容,更多请关注其它相关文章!