AtCoder Navbar Restrictor

restricts navbar width

Verze ze dne 27. 07. 2024. Zobrazit nejnovější verzi.

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