Atcoder Easy Accordion

Atcoderのアコーディオンメニューを、マウスのホバーで開けるようにします

ของเมื่อวันที่ 20-04-2025 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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         Atcoder Easy Accordion
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Atcoderのアコーディオンメニューを、マウスのホバーで開けるようにします
// @author       Rac
// @license      MIT
// @match        https://atcoder.jp/*
// @exclude      /^https://atcoder\.jp/[^#?]*/json/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    if(document.getElementsByClassName("header-mypage_btn").length != 0) {
        window.scrollTo=()=>{};
    }

    document.querySelectorAll(".nav > li:not(.pull-right)").forEach((element) => {
        element.addEventListener("mouseenter", () => {
            setTimeout(() => {
                element.classList.add("open");
            }, 10);
        });
        element.addEventListener("mouseleave", () => {
            element.classList.remove("open");
        });
    });
    {
        const element = document.getElementsByClassName("header-mypage_btn")[0];
        const element_ac = document.getElementsByClassName("header-mypage_detail")[0];
        if(element && element_ac) {
            let flag1 = false;
            let flag2 = false;
            element.addEventListener("mouseenter", () => {
                flag2 = false;
                if(!element.classList.contains("active")) {
                    setTimeout(() => {
                        if(!element.classList.contains("active")) element.click();
                    }, 10);
                }
            });
            element.addEventListener("mouseleave", () => {
                flag1 = true;
                setTimeout(() => {
                    if(flag1 && element.classList.contains("active")) element.click();
                }, 10);
            });
            element_ac.addEventListener("mouseenter", () => {
                flag1 = false;
                if(!element.classList.contains("active")) element.click();
            });
            element_ac.addEventListener("mouseleave", () => {
                flag2 = true;
                setTimeout(() => {
                    if(flag2 && element.classList.contains("active")) element.click();
                }, 10);
            });
        }
    }
})();