Files
RiverRobot/AutoLoginClarity.js
2019-06-12 07:47:55 -05:00

65 lines
3.0 KiB
JavaScript

// ==UserScript==
// @name AutoLoginClarity
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically pull data out of Riverbed for the previous day.
// @author joe.tretter@kcc.com
// @match https://clarity.kcc.com/niku/*
// ==/UserScript==
(function() {
'use strict';
// no cleartext password
function encryptXor(text, key) {
return Array.from(
text,
(c, i) => String.fromCharCode(c.charCodeAt() ^ key.charCodeAt(i % key.length))
).join('');
}
// if the login dialog pops up -> log in.
function loginThread(credentials) {
let myInterval;
myInterval= window.setInterval(()=>{
let userNameField = document.getElementById("ppm_login_username");
let userPasswordField = document.getElementById("ppm_login_password");
let userLoginButton = document.getElementById("ppm_login_button");
if (userNameField !== null) {
// If we don't have credentials saved we ask for credentials.
// If the login dialog comes up again in less than 10 seconds we assume the password changed and don't retry automatically to prevent account locking.
if ((credentials === null) || ((localStorage.getItem("LastLoginDate") !== null) && ((new Date().getTime() - localStorage.getItem("LastLoginDate")) / 1000 < 10 ))) {
clearInterval(myInterval);
window.document.title="[AutoLoginClarity] Login unsuccessful.";
console.log("Login unsuccessful.");
userLoginButton.value="AutoLoginClarity: Save Credentials + Login";
// Credentials are stored encrypted in the Browsen's localstorage (yes, it's NOT safe, but it's a hurdle)
userLoginButton.onclick=function(){
credentials={username:userNameField.value,password:userPasswordField.value};
localStorage.setItem("Credentials",encryptXor(JSON.stringify(credentials), '5346245634634765377'));
console.log('Credentials Saved.');
window.location.reload();
};
userLoginButton.onkeydown=onclick;
} else {
//window.document.title="[AutoLoginClarity] Logging In";
localStorage.setItem("LastLoginDate",new Date().getTime())
clearInterval(myInterval);
userNameField.value=credentials.username;
userPasswordField.value=credentials.password;
userLoginButton.click();
}
}
},1000);
}
// Password is encrypted with XOR to preent "accidental" revelation
let credentials=localStorage.getItem("Credentials");
if (credentials!==null) { credentials=JSON.parse(encryptXor(credentials, '5346245634634765377')); }
console.log(credentials);
loginThread(credentials);
})();