AtCoder Navbar Restrictor

restricts navbar width

Від 27.07.2024. Дивіться остання версія.

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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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.2
// @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];
    if(!$contestTitle) return;

    $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);
        $contestTitle.style["max-width"] = `${width}px`;
    });

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