Fix SharePoint "Sign in to continue" bug

Automatically clicks the 'Not now' button on SharePoint login pop-ups.

// ==UserScript==
// @name         Fix SharePoint "Sign in to continue" bug
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically clicks the 'Not now' button on SharePoint login pop-ups.
// @author       Gemini 2.5 Pro & Lukas Tesar <[email protected]>
// @match        https://*.sharepoint.com/*
// @icon         https://www.microsoft.com/favicon.ico
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const buttonSelector = "div.ms-Dialog-actions .ms-Button--default";

    const findAndClick = () => {
        const button = document.querySelector(buttonSelector);

        // Check if the button exists and is visible on the page.
        // An element's offsetParent is null if it or its ancestors are hidden via `display: none`.
        if (button && button.offsetParent !== null) {
            button.click();
        }
    };

    const observerCallback = () => {
        findAndClick();
    };

    /*
     * Configure the observer to watch for:
     * - childList: New elements being added/removed from the DOM.
     * - attributes: Changes to element attributes (like 'style' or 'class' for visibility).
     * - subtree: The entire document body and all its descendants.
    */
    const observerConfig = {
        childList: true,
        attributes: true,
        subtree: true,
    };

    const observer = new MutationObserver(observerCallback);
    observer.observe(document.body, observerConfig);

    // Run once on initial script load in case the popup is already present.
    findAndClick();
})();