Skip to content

Commit

Permalink
Now instantly presses the Microsoft button after the document have lo…
Browse files Browse the repository at this point in the history
…aded. Also the scope is narrowed a little bit
  • Loading branch information
on committed Aug 19, 2025
1 parent 7f34325 commit 0c339e1
Showing 1 changed file with 7 additions and 119 deletions.
126 changes: 7 additions & 119 deletions feide-microsoft.user.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
})();

0 comments on commit 0c339e1

Please sign in to comment.