ctfshow-auxiliary

show again!

  1. // ==UserScript==
  2. // @name ctfshow-auxiliary
  3. // @namespace http://peterzhang.top/
  4. // @version 0.3
  5. // @description show again!
  6. // @author PeterZhang<1809909143@qq.com>
  7. // @match https://ctf.show/challenges
  8. // @icon https://www.google.com/s2/favicons?domain=google.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Your code here...
  16. const prefix = 't-';
  17.  
  18. // style
  19. $('head').append(
  20. `<style>
  21. .content-index-outer{
  22. position: absolute;
  23. right: -80px;
  24. top: 120px;
  25. height: 100%;
  26. }
  27. .content-index{
  28. position: sticky;
  29. position: -webkit-sticky;
  30. top: 80px;
  31. padding: 5px;
  32. background-color: #eeeeee;
  33. overflow-y: scroll;
  34. }
  35. .my-link{
  36. cursor: pointer;
  37. font-size: 0.8em;
  38. }
  39. .my-link:hover{
  40. background-color: #b9bcbf;
  41. }
  42. </style>`
  43. );
  44.  
  45. function refreshContentIndex(records, observer) {
  46. if (records[0].target.style.display !== 'none' || $('#challenges-board .category-header h3').length < 1) {
  47. return;
  48. }
  49. const outerDiv = $(`<div class="content-index-outer"></div></div>`);
  50. const div = $(`<div class="content-index">`);
  51. div[0].style.maxHeight = (window.innerHeight - 100) + 'px';
  52. outerDiv.append(div);
  53. $('#challenges-board').append(outerDiv);
  54. $('#challenges-board .category-header h3').each(function () {
  55. $(this).attr('id', `${prefix}${$(this).text()}`);
  56. const a = $(`
  57. <div class="my-link">${$(this).text()}</div>
  58. `);
  59. a.click(() => {
  60. $('html, body').animate({scrollTop: $(this).offset().top - 80}, 200);
  61. });
  62. div.append(a);
  63. });
  64. }
  65.  
  66. let observer = new MutationObserver(refreshContentIndex);
  67. observer.observe($('#chall-load-spinner')[0], {attributes: true});
  68.  
  69. // 一些优化
  70. $('#pages-board').css('top', '70px');
  71. })();