Kattis Stats Links

Adds some convenience links to stats in problems in Kattis

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
}