AtCoder Navbar Restrictor

restricts navbar width

目前为 2024-07-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         AtCoder Navbar Restrictor
// @namespace    https://twitter.com/KakurenboUni
// @version      0.0.1
// @description  restricts navbar width
// @author       uni_kakurenbo
// @match        https://atcoder.jp/contests/**
// @license      MIT
// @supportURL   https://twitter.com/KakurenboUni
// ==/UserScript==

(function() {
    'use strict';

    const $navbar =document.getElementById("navbar-collapse");

    if(!$navbar) return;


    const $contestTitle = document.getElementsByClassName("contest-title")[0];

    $contestTitle.style["text-overflow"] = "ellipsis"
    $contestTitle.style["text-wrap"] = "nowrap"
    $contestTitle.style["overflow-x"] = "clip"

    const observer = new ResizeObserver(() => {
        const $navbarBrand = document.getElementsByClassName("navbar-brand")[0];
        const $navbarRight = document.getElementsByClassName("navbar-right")[0];

        if(!$navbarBrand || !$navbarRight) return;

        const width = $navbar.offsetWidth - ($navbarRight.offsetWidth + $navbarBrand.offsetWidth);

        Array.from(document.getElementsByClassName("contest-title")).forEach(($e) => {
            $contestTitle.style["max-width"] = `${width}px`;
        })
    });

    observer.observe($navbar);
})();