AtCoder Navbar Restrictor

restricts navbar width

  1. // ==UserScript==
  2. // @name AtCoder Navbar Restrictor
  3. // @namespace https://twitter.com/KakurenboUni
  4. // @version 0.0.3
  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["overflow-x"] = "clip"
  22. $contestTitle.style["text-overflow"] = "ellipsis"
  23. $contestTitle.style["text-wrap"] = "nowrap"
  24.  
  25. const observer = new ResizeObserver(() => {
  26. const $navbarBrand = document.getElementsByClassName("navbar-brand")[0];
  27. const $navbarRight = document.getElementsByClassName("navbar-right")[0];
  28. if(!$navbarBrand || !$navbarRight) return;
  29.  
  30. const width = $navbar.offsetWidth - ($navbarRight.offsetWidth + $navbarBrand.offsetWidth);
  31. $contestTitle.style["max-width"] = `${width}px`;
  32. });
  33.  
  34. observer.observe($navbar);
  35. })();