Attendance: autoswitch

Switch between attendance sessions without asking.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Attendance: autoswitch
// @namespace    https://github.com/nate-kean/
// @version      2025.11.3
// @description  Switch between attendance sessions without asking.
// @author       Nate Kean
// @match        https://jamesriver.fellowshiponego.com/attendance/recent
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fellowshiponego.com
// @grant        none
// @license      MIT
// ==/UserScript==

(async function() {
    function delay(ms) {
        return new Promise((resolve) => setTimeout(resolve, ms));
    }

    async function waitForElement(selector, pollingRateMs=100, parent=document) {
        let el;
        while (true) {
            el = parent.querySelector(selector);
            if (el) return el;
            await delay(pollingRateMs);
        }
    }

    async function elementGone(selector, pollingRateMs=100, parent=document) {
        let el;
        while (true) {
            el = parent.querySelector(selector);
            if (!el) return;
            await delay(pollingRateMs);
        }
    }

    while (true) {
        const headcountHolder = await waitForElement(".headcount-holder");

        const maybeContinueButton = await Promise.any([
            waitForElement("button[type='submit']"), // "Confirm" window pops up
            elementGone(".headcount-holder"), // User closes the attendance pane
        ]);
        if (maybeContinueButton) {
            maybeContinueButton.click();
        }
    }
})();