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

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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 });
    }
})();