From 0c339e1999a662d85bdbe3bb1522630d2beaaf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Andreas=20Nilsen?= Date: Tue, 19 Aug 2025 08:30:06 +0200 Subject: [PATCH] Now instantly presses the Microsoft button after the document have loaded. Also the scope is narrowed a little bit --- feide-microsoft.user.js | 126 +++------------------------------------- 1 file changed, 7 insertions(+), 119 deletions(-) diff --git a/feide-microsoft.user.js b/feide-microsoft.user.js index aed0fbd..4ce6257 100644 --- a/feide-microsoft.user.js +++ b/feide-microsoft.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @name Feide - Auto-Press Microsoft Sign-In. // @namespace https://git.ntnu.no/M365-Drift/MonkeyMagic -// @version 1.1.2 -// @description Automatically press the Microsoft sign-in button after a countdown, with options to cancel or trigger manually. Use `Ctrl` + `Enter` to skip countdown. Use `Esc` to cancel countdown. To set a custom countdown, use `Ctrl` + `Shift` + `S`. +// @version 1.1.3 +// @description Automatically press the Microsoft sign-in button. // @author Øyvind Nilsen (on@ntnu.no) -// @match https://idp.feide.no/simplesaml/* +// @match https://idp.feide.no/simplesaml/module.php/* // @icon https://www.google.com/s2/favicons?sz=64&domain=feide.no // @grant none // @run-at document-end @@ -16,121 +16,9 @@ 'use strict'; const button = document.getElementById('microsoft-signin-button'); - if (!button) return; - - let countdown = getCountdown(); - - if (countdown === null) { - countdown = 1; - } - - let countdownInterval; - - function updateButtonText() { - button.value = `Use work or school account (${countdown}s)`; - } - - function storeCountdown(value) { - localStorage.setItem('countdown', value); + if (!button) { + return; + } else { + button.click(); } - - // Function to retrieve the countdown value from local storage - function getCountdown() { - return localStorage.getItem('countdown'); - } - - function startCountdown() { - updateButtonText(); - countdownInterval = setInterval(() => { - countdown--; - if (countdown <= 0) { - updateButtonText(); - clearInterval(countdownInterval); - button.click(); - } else { - updateButtonText(); - } - }, 1000); - } - - function stopCountdown() { - clearInterval(countdownInterval); - button.value = 'Use work or school account'; - } - - function showCountdownInput() { - const overlay = document.createElement('div'); - overlay.style.position = 'fixed'; - overlay.style.top = '0'; - overlay.style.left = '0'; - overlay.style.width = '100%'; - overlay.style.height = '100%'; - overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; - overlay.style.display = 'flex'; - overlay.style.justifyContent = 'center'; - overlay.style.alignItems = 'center'; - overlay.style.zIndex = '1000'; - - const box = document.createElement('div'); - box.style.backgroundColor = 'grey'; - box.style.padding = '20px'; - box.style.borderRadius = '10px'; - box.style.textAlign = 'center'; - - const label = document.createElement('label'); - label.textContent = 'Set custom countdown'; - label.style.display = 'block'; - label.style.marginBottom = '10px'; - label.style.color = 'white'; - - const input = document.createElement('input'); - input.type = 'number'; - input.min = '1'; - input.value = countdown; - input.style.marginBottom = '10px'; - input.style.width = '100%'; - - const saveButton = document.createElement('button'); - saveButton.textContent = 'Save'; - saveButton.style.marginRight = '10px'; - - const cancelButton = document.createElement('button'); - cancelButton.textContent = 'Cancel'; - - saveButton.addEventListener('click', function() { - const newCountdown = parseInt(input.value, 10); - if (!isNaN(newCountdown) && newCountdown > 0) { - countdown = newCountdown; - storeCountdown(countdown); - updateButtonText(); - } - document.body.removeChild(overlay); - }); - - cancelButton.addEventListener('click', function() { - document.body.removeChild(overlay); - }); - - box.appendChild(label); - box.appendChild(input); - box.appendChild(saveButton); - box.appendChild(cancelButton); - overlay.appendChild(box); - document.body.appendChild(overlay); - - input.focus(); - } - - document.addEventListener('keydown', function(event) { - if (event.key === 'Escape') { - stopCountdown(); - } else if (event.ctrlKey && event.key === 'Enter') { - clearInterval(countdownInterval); - button.click(); - } else if (event.ctrlKey && event.shiftKey && event.key === 'S') { - showCountdownInput(); - } - }); - - startCountdown(); })(); \ No newline at end of file