AtCoder Navbar Restrictor

restricts navbar width

As of 27.07.2024. See ბოლო ვერსია.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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 Navbar Restrictor
// @namespace    https://twitter.com/KakurenboUni
// @version      0.0.0
// @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 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) => {
            $e.style["max-width"] = `${width}px`;
            $e.style["text-overflow"] = "ellipsis"
            $e.style["text-wrap"] = "nowrap"
            $e.style["overflow-x"] = "clip"
        })
    });

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