Created
March 12, 2022 00:38
-
-
Save 42Willow/524a7c3903d215ef28bd19016a9c4cba to your computer and use it in GitHub Desktop.
Batheo auto-login (Chrome extension)
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
chrome.extension.onRequest.addListener(onRequest); | |
function onRequest(request, sender, sendResponse) { | |
if (request.eventName == "getSettings") { | |
sendResponse({user: getStorage("user"), pass: getStorage("pass"), autof: getStorage("fill")}); | |
} else { | |
sendResponse({}); | |
} | |
} | |
function getStorage(type) { | |
data = localStorage.getItem("batheo_" + type); | |
return data; | |
} |
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
var userName = null; | |
var passWord = null; | |
var autoFillOnly = false; | |
var getUrl = document.location.href; | |
chrome.extension.sendRequest( { eventName: "getSettings" }, | |
function(response) { | |
userName = response.user; | |
passWord = response.pass; | |
autoFillOnly = response.autof; | |
checkIfAutoUrl(); | |
} | |
); | |
function checkIfAutoUrl() { | |
if (getUrl.search("#autologin~") >= 1) { // If Url contains autologin parameters, continue, else start next function and end. | |
var cutUrl = getUrl.split('~'); // Separates the parameters from Url. | |
var parts = cutUrl[1].split('&'); // Separates the username and password from the parameters. | |
userName = parts[0]; // userName is equal to 1st parameter. | |
passWord = parts[1]; // passWord is equal to 2nd parameter. | |
} | |
if (userName != "" || passWord != "") { // Only autoLogin if the username or password isn't null. This is to prevent it from | |
autoLogin(); // unecessarily trying to log you in with incorrect info. | |
} | |
} | |
function autoLogin() { | |
var emailEle = document.getElementById("email"); // Set email box element as a variable. | |
var passEle = document.getElementById("pw"); // Set password box element as a variable. | |
emailEle.setAttribute("value", userName); // Fill out the email box with userName. | |
passEle.setAttribute("value", passWord); // Fill out the password box with passWord. | |
if (!autoFillOnly) { // Only click log-in if autoFillOnly is false. | |
location.href = "javascript:void(login());"; // Press the login button. | |
} | |
} |
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
<html> | |
<head><title>Settings</title></head> | |
<script type="text/javascript" src="options.js"></script> | |
<style type="text/css"> | |
lt { | |
position:relative; | |
left:150px; | |
} | |
pt { | |
position:relative; | |
left:20px; | |
} | |
</style> | |
<body > | |
<lt> <h1> Settings </h1> </lt> <br> | |
<pt> Username: <input id="UsernameBox" style="width:300px;" type="text"> </pt> <br> | |
<pt> Password: <input id="PasswordBox" style="width:300px;" type="password"> </pt> <br> | |
<pt> <input type="checkbox" id="AutoFill" /> Auto-Fill only? (will fill in data but not log-in) </pt> <br></br> | |
<lt> <pt><pt> <button type="button" id="SubmitBut">Save</button> </pt></pt> </lt> <br> | |
</body> | |
</html> |
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
window.addEventListener("load", load_options, false); | |
document.getElementById("SubmitBut").addEventListener("click", save_options, false); | |
function load_options() { | |
var userName = localStorage.getItem("batheo_user"); | |
var passWord = localStorage.getItem("batheo_pass"); | |
var autoFill = localStorage.getItem("batheo_fill"); | |
document.getElementById("UsernameBox").setAttribute("value", userName); | |
document.getElementById("PasswordBox").setAttribute("value", passWord); | |
document.getElementById("AutoFill").checked=autoFill; | |
} | |
function save_options() { | |
var userBox = document.getElementById("UsernameBox").value; | |
var passBox = document.getElementById("PasswordBox").value; | |
var autoFillCheck = document.getElementById("AutoFill").checked; | |
localStorage.setItem("batheo_user", userBox); | |
localStorage.setItem("batheo_pass", userBox); | |
localStorage.setItem("batheo_fill", autoFillCheck); | |
alert("Log-in successfully saved!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment