Kattis Stats Links

Adds some convenience links to stats in problems in Kattis

  1. // ==UserScript==
  2. // @name Kattis Stats Links
  3. // @description Adds some convenience links to stats in problems in Kattis
  4. // @version 1
  5. // @include https://open.kattis.com/*
  6. // @namespace https://greasyfork.org/users/8233
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11.  
  12. // create stat link from given URL
  13. function makeStatLinkNode(url) {
  14. var ret = document.createElement('a');
  15. ret.href = url + '/statistics';
  16. ret.innerText = ' (stats)';
  17. return ret;
  18. }
  19.  
  20.  
  21. // add stat link behind any <a> element that has href going to URL that has a "problems/(somename)" part
  22. var links = document.querySelectorAll('a');
  23. for (const a of links) {
  24. if (a.getAttribute('href') !== null && a.getAttribute('href').match(/problems\/[0-9a-z]*/i) !== null) {
  25. var newa = makeStatLinkNode(a.getAttribute('href'));
  26. a.parentElement.appendChild(newa);
  27. }
  28. }
  29.  
  30.  
  31. // add stat link behind a problm name in problem page itself
  32. var urlparts = window.location.toString().split('/');
  33. if (urlparts[urlparts.length - 2] == 'problems') {
  34. var heading = document.querySelector('.book-page-heading');
  35. var newa = makeStatLinkNode(window.location);
  36. heading.appendChild(newa);
  37. }