icoremail.net 校园邮箱自动选择域名

自动选择你学校的域名免除烦恼,默认为 xiaoyou.hust.edu.cn,请按需修改脚本

// ==UserScript==
// @name         icoremail.net 校园邮箱自动选择域名
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动选择你学校的域名免除烦恼,默认为 xiaoyou.hust.edu.cn,请按需修改脚本
// @author       Ryan
// @match        https://edu.icoremail.net/coremail/index.jsp*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=icoremail.net
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const domain = 'xiaoyou.hust.edu.cn';

    function setDomain() {
        const m = document.querySelector(`[data-id="${domain}"]`);
        if (m) {
            m.click();
            return true;
        }
        return false; // Element not found
    }

    // Initial attempt to set domain
    if (!setDomain()) {
        // If element is not found, use MutationObserver to monitor changes
        const observer = new MutationObserver((mutationsList, observer) => {
            if (setDomain()) {
                observer.disconnect(); // Stop observing once the element is found and updated
            }
        });

        // Start observing the document for added nodes
        observer.observe(document.body, { childList: true, subtree: true });
    }
})();