AtCoder Navbar Restrictor

restricts navbar width

Versione datata 27/07/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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