Separate lib, new problems and script for web
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// ==UserScript==
|
||||
// @name USACO Auto-Login
|
||||
// @namespace usaco-autologin
|
||||
// @version 1.0
|
||||
// @description Automatically signs in to usaco.org when logged out
|
||||
// @match http://usaco.org/*
|
||||
// @match https://usaco.org/*
|
||||
// @match http://www.usaco.org/*
|
||||
// @match https://www.usaco.org/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
// ---- Fill these in ----
|
||||
const USERNAME = "YOUR_USERNAME";
|
||||
const PASSWORD = "YOUR_PASSWORD";
|
||||
// -----------------------
|
||||
|
||||
// If a logout link exists, we're already signed in.
|
||||
if (document.querySelector('a[href*="logout"]')) return;
|
||||
|
||||
const uname = document.querySelector('input[name="uname"]');
|
||||
const pword = document.querySelector(
|
||||
'input[name="password"], input[name="pword"]',
|
||||
);
|
||||
if (!uname || !pword) return;
|
||||
|
||||
// Avoid an infinite reload loop if credentials are wrong:
|
||||
// only auto-submit once per minute.
|
||||
const last = sessionStorage.getItem("usacoAutoLoginAt");
|
||||
if (last && Date.now() - Number(last) < 60000) return;
|
||||
sessionStorage.setItem("usacoAutoLoginAt", String(Date.now()));
|
||||
|
||||
uname.value = USERNAME;
|
||||
pword.value = PASSWORD;
|
||||
|
||||
const form = uname.closest("form");
|
||||
if (form) {
|
||||
// Prefer clicking the submit button so any onclick handlers run.
|
||||
const btn = form.querySelector(
|
||||
'input[type="submit"], button[type="submit"], button',
|
||||
);
|
||||
if (btn) btn.click();
|
||||
else form.submit();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user