Kattis Stats Links

Adds some convenience links to stats in problems in Kattis

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Kattis Stats Links
// @description Adds some convenience links to stats in problems in Kattis
// @version 1
// @include https://open.kattis.com/*
// @namespace https://greasyfork.org/users/8233
// @grant    none
// @license  MIT
// ==/UserScript==


// create stat link from given URL
function makeStatLinkNode(url) {
  var ret = document.createElement('a');
  ret.href = url + '/statistics';
  ret.innerText = ' (stats)';
  return ret;
}


// add stat link behind any <a> element that has href going to URL that has a "problems/(somename)" part
var links = document.querySelectorAll('a');
for (const a of links) {
  if (a.getAttribute('href') !== null && a.getAttribute('href').match(/problems\/[0-9a-z]*/i) !== null) {
    var newa = makeStatLinkNode(a.getAttribute('href'));
    a.parentElement.appendChild(newa);
  }
}


// add stat link behind a problm name in problem page itself
var urlparts = window.location.toString().split('/');
if (urlparts[urlparts.length - 2] == 'problems') {
  var heading = document.querySelector('.book-page-heading');
  var newa = makeStatLinkNode(window.location);
  heading.appendChild(newa);
}