Skip to content

Instantly share code, notes, and snippets.

@Cxarli
Created February 3, 2016 19:14
Show Gist options
  • Save Cxarli/b6d2cda5b190ec1466c5 to your computer and use it in GitHub Desktop.
Save Cxarli/b6d2cda5b190ec1466c5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Magister
// @namespace magister
// @description Tools for staying logged in on Magister
// @include https://*.magister.net/*
// @version 1.7.1
// @grant none
// ==/UserScript==
// Enter Magister username and password here
const username = "810....";
const password = ".......";
// Function for logging in
function reLogin() {
let href = location.href;
if (/#\/inloggen/.test(href)) { // Test for inlog screen
// Enter credentials
let passfield = $("#password");
let loginbutton = $(".btn-primary3")[0];
if ((passfield !== undefined) && (loginbutton !== undefined)) {
let scope = passfield.scope();
scope.credentials.Gebruikersnaam = username;
scope.credentials.Wachtwoord = password;
scope.credentials.IngelogdBlijven = true;
loginbutton.click();
}
return true;
} else {
// Page failed to load -> Not logged in
if ($(".view")[0].children.length == 0) {
// Send to login screen
location.href = location.origin;
}
}
return false;
};
function hideDialog() {
// var contentScope = angular.element($('.content')[0]).scope(;
let x=[];
if(!( (x=$('.content')) && x.length>0 && (x=x[0]) && (x=angular.element(x)) && (x=x.scope()) )) {
// Failed to get item
return false;
}
var contentScope = x;
// If there is a dialog
if ( contentScope.isDialogVisible ) {
let passfield = $("#aanmelden-dlg-password");
let button = $(".primary-button")[0];
if((passfield != undefined) && (button != undefined)) {
let scope = passfield.scope().$parent;
scope.vm.Gebruikersnaam = username;
scope.vm.Wachtwoord = password;
scope.vm.IngelogdBlijven = true;
button.click();
}
}
return false;
};
var functions = [hideDialog, reLogin];
function main() {
// Remove if function responds true
functions = functions.filter(func => !func());
if (functions.length > 0) {
// If we have more functions left, try again in 2 seconds
setTimeout(main, 2000);
}
};
// Wait 4 seconds for page to load
setTimeout(main, 4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment