Greasy Fork

Greasy Fork is available in English.

Shorten Names for Proving for Fun

Hide annoyingly long names.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Shorten Names for Proving for Fun
// @namespace   do-proof-in-tum-de-addons
// @match       https://do.proof.in.tum.de/*
// @grant       none
// @version     0.1
// @author      Max Lang
// @license     0BSD
// @description Hide annoyingly long names.
// ==/UserScript==


(function() {

  const rules = [
    [".navbar-text strong", /(\S+)/d],
    [".scoretnb, .scoretn", /(\S+)/d],
    [".container div", /Submitted by (\S+) @/d]
  ];

  for (const [selector, pattern] of rules) {
    for (const el of document.querySelectorAll(selector)) {
      for (const child of [...el.childNodes]) {
        if (child.nodeType != 3) continue;
        const match = child.textContent.match(pattern);
        if (match === null) continue;

        const span = document.createElement("span");
        const spanText = child.textContent.substring(...match.indices[1]);
        span.textContent = spanText;
        span.title = spanText;

        span.style.display = "inline-block";
        span.style.width = "10em";
        span.style.overflow = "hidden";
        span.style.textOverflow = "ellipsis";
        span.style.verticalAlign = "bottom";

        child.replaceWith(
          child.textContent.substring(0, match.indices[1][0]),
          span,
          child.textContent.substring(match.indices[1][1])
        );
      }
    }
  }

})();