Last active
May 6, 2024 14:22
-
-
Save dcdunkan/1e57baf2d913b0d93b73fa52edd11df6 to your computer and use it in GitHub Desktop.
Script for logging in automatically each time I open the damn site cuz the session is expired very quickly.
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
// ==UserScript== | |
// @name etlab auto login | |
// @namespace Violentmonkey Scripts | |
// @match https://*.etlab.in/* | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @version 0.4 | |
// @author Dunkan <https://github.com/dcdunkan> | |
// @description 3/12/2024, 2:32:52 AM | |
// @run-at document-end | |
// @homepageURL https://gist.github.com/dcdunkan/1e57baf2d913b0d93b73fa52edd11df6 | |
// @updateURL https://gist.githubusercontent.com/dcdunkan/1e57baf2d913b0d93b73fa52edd11df6/raw/etlab-auto-login.userscript.js | |
// @downloadURL https://gist.githubusercontent.com/dcdunkan/1e57baf2d913b0d93b73fa52edd11df6/raw/etlab-auto-login.userscript.js | |
// ==/UserScript== | |
(function() { | |
console.log("AUTO-LOGIN USERSCRIPT IS RUNNING!"); | |
// LOGIN PAGE | |
if (window.location.pathname.startsWith("/user/login")) { | |
// setup credentials | |
const hasSetup = GM_getValue("hasSetup", false); | |
if (!hasSetup) { | |
window.alert("Enter the username and password in the next prompts. Disable the script if you decide to stop using it."); | |
let username = "", password = ""; | |
do username = window.prompt("Username"); while (username.trim() === ""); | |
do password = window.prompt("Password"); while (password.trim() === ""); | |
GM_setValue("username", username); | |
GM_setValue("password", password); | |
GM_setValue("askEverytime", window.confirm("Do you want me to ask you everytime before I login you automatically? (Choose wisely!)")); | |
GM_setValue("hasSetup", true); | |
window.alert("DONE! Clear this script's storage if you wanna reset all this or change credentials"); | |
} | |
if (localStorage.getItem("triggeredByLogout") === "true") | |
if (!window.confirm("You manually logged out last time. Do you want to use auto-login?")) | |
return; | |
else if (GM_getValue("askEverytime", false)) | |
if (!window.confirm("Use auto-login?")) | |
return; | |
localStorage.removeItem("triggeredByLogout"); | |
console.log("LOGGING IN..."); | |
document.getElementById("LoginForm_username").value = GM_getValue("username", ""); | |
document.getElementById("LoginForm_password").value = GM_getValue("password", ""); | |
document.getElementById("login-form").submit(); | |
console.log("LOGGED IN AUTOMATICALLY as", GM_getValue("username")); | |
} else { | |
const logoutLinks = document.getElementsByTagName("a"); | |
for (const a of logoutLinks) { | |
if (a.pathname === "/user/logout") { | |
const onClick = 'if(window.confirm("Do you want to log out?")){localStorage.setItem("triggeredByLogout","true");window.location.href="' + a.href + '";}'; | |
a.outerHTML = "<button onClick='" + onClick + "'>Logout</button>" | |
break; | |
} | |
} | |
} | |
if (window.location.pathname.startsWith("/survey/user/answer/") && | |
Array.from(Array.from(document.getElementsByClassName("answer")).map((x) => Array.from(x.children))).map((x) => x.filter((x) => /Option\[\d+\]/.test(x.name))).flat().length && | |
window.confirm("Do you want to prefill options?")) { | |
let i = 0; | |
let option = 1; | |
do option = Number(window.prompt((i > 0 ? "INVALID input: " : "") + "Enter 1 to 5", "x").trim()), i += 1; while (isNaN(option) || option < 1 || option > 5); | |
Array.from(Array.from(document.getElementsByClassName("answer")).map((x) => Array.from(x.children))).map((x) => x.filter((x) => /Option\[\d+\]/.test(x.name))).map((x) => x[option-1].click()) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment