-
-
Save jesusjda/fbf3bda3952632cebd6e to your computer and use it in GitHub Desktop.
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
/*! cv-autologin.user.js v1.0 | (c) 2014 Pablo Cabeza | MIT license: http://opensource.org/licenses/mit-license.php */ | |
// ==UserScript== | |
// @name cv-autologin | |
// @namespace https://gist.github.com/2b50eaf5e4912cbf8d35 | |
// @version 1.0 | |
// @description To login automatically into UCM unified login | |
// @author Pablo Cabeza | |
// @include https://sso.ucm.es/simplesaml/module.php/userpasswordcaptcha/loginuserpass.php* | |
// @include http://www.ucm.es/campusvirtual* | |
// @include https://www.ucm.es/campusvirtual* | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.js | |
// @updateURL https://gist.github.com/PCabeza/2b50eaf5e4912cbf8d35/raw/cv-autologin.user.js | |
// @downloadURL https://gist.github.com/PCabeza/2b50eaf5e4912cbf8d35/raw/cv-autologin.user.js | |
// ==/UserScript== | |
(function(win,doc,$) { | |
var logindata = ['user','pass']; | |
var elids = ["#username","#password"]; | |
var redirect_url = "www.ucm.es/campusvirtual" | |
function loginErrors() { return $('img[src$="gtk-dialog-error.48x48.png"]').length!==0; } | |
function setData(call){ | |
if(logindata.length) { | |
$.each(elids,function(i,v) { $(v).val(logindata[i]); }); | |
call(); | |
} | |
else { // todo check if focus is in user of password | |
var val = true; | |
$.each(elids,function(i,v) { console.log($(v).val()); val = val && Boolean($(v).val()); } ); | |
console.log(val); | |
if(val) call(); | |
else win.setTimeout(function(){ setData(call); },500); | |
} | |
} | |
function submit(){ $('form[name=f]').submit(); } | |
function login() { if(!loginErrors()) setData(submit); } | |
function disableCaptcha() { | |
$.each(elids, function(i,v) { $(v).removeAttr('onblur'); }); | |
} | |
$(doc).ready(function(){ | |
var uri = win.location.host + win.location.pathname; | |
// If we are of cv redirect | |
if(uri==redirect_url||uri==redirect_url+"/") $('#login form [type=submit]').click(); | |
// If we are on login form | |
else { | |
disableCaptcha(); | |
login(); | |
} | |
}); | |
})(window,document,jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment