AtCoder Navbar Restrictor

restricts navbar width

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

  1. // ==UserScript==
  2. // @name AtCoder Navbar Restrictor
  3. // @namespace https://twitter.com/KakurenboUni
  4. // @version 0.0.2
  5. // @description restricts navbar width
  6. // @author uni_kakurenbo
  7. // @match https://atcoder.jp/contests/**
  8. // @license MIT
  9. // @supportURL https://twitter.com/KakurenboUni
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const $navbar =document.getElementById("navbar-collapse");
  16. if(!$navbar) return;
  17.  
  18. const $contestTitle = document.getElementsByClassName("contest-title")[0];
  19. if(!$contestTitle) return;
  20.  
  21. $contestTitle.style["text-overflow"] = "ellipsis"
  22. $contestTitle.style["text-wrap"] = "nowrap"
  23. $contestTitle.style["overflow-x"] = "clip"
  24.  
  25. const observer = new ResizeObserver(() => {
  26. const $navbarBrand = document.getElementsByClassName("navbar-brand")[0];
  27. const $navbarRight = document.getElementsByClassName("navbar-right")[0];
  28.  
  29. if(!$navbarBrand || !$navbarRight) return;
  30.  
  31. const width = $navbar.offsetWidth - ($navbarRight.offsetWidth + $navbarBrand.offsetWidth);
  32. $contestTitle.style["max-width"] = `${width}px`;
  33. });
  34.  
  35. observer.observe($navbar);
  36. })();