fsharp.github.io - Add Summary Nav To Top Of Page

13/04/2022, 2:14:00 pm

目前为 2022-11-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name fsharp.github.io - Add Summary Nav To Top Of Page
  3. // @namespace Violentmonkey Scripts
  4. // @match https://fsharp.github.io/fsharp-core-docs/reference/*
  5. // @match https://fsprojects.github.io/FSharpPlus/*
  6. // @match http://fsprojects.github.io/FSharpPlus/reference/*
  7. // @match https://fsprojects.github.io/FSharpx.Collections/reference/*
  8. // @grant GM_addStyle
  9. // @version 1.0
  10. // @author -
  11. // @description 13/04/2022, 2:14:00 pm
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. GM_addStyle(`.hide {display:none;}`)
  16.  
  17. const button = document.createElement('button')
  18. button.setAttribute('style', `display: block;margin-bottom: 0.6rem;`)
  19. button.textContent = 'Show Summaries'
  20.  
  21. button.onclick = () => {
  22. Array.from(document.querySelectorAll('.toc-summary')).forEach(elem => {
  23. elem.classList.toggle('hide')
  24. })
  25. }
  26.  
  27. const apiAnchorLinks = Array.from(document.querySelectorAll('.fsdocs-member-usage code a[href^="#"]'))
  28.  
  29. const topNavAnchorLinksContainer = document.createElement('div')
  30. topNavAnchorLinksContainer.setAttribute('class', 'anchor-nav-container')
  31. topNavAnchorLinksContainer.setAttribute('style', 'display:inline-flex;flex-direction:column;')
  32.  
  33. document.querySelector('.fsdocs-xmldoc').insertAdjacentElement('afterend', topNavAnchorLinksContainer)
  34. document.querySelector('#fsdocs-content>div').insertBefore(button, document.querySelector('.anchor-nav-container'))
  35.  
  36. apiAnchorLinks.forEach(elem => {
  37.  
  38. const clonedElem = elem.cloneNode(true)
  39. clonedElem.querySelector('code span>span')?.remove()
  40.  
  41. const divContainer = document.createElement('div')
  42. divContainer.setAttribute('style', `display: flex;flex-direction: column;`)
  43.  
  44.  
  45. const summary = elem.closest('.fsdocs-member-usage').nextElementSibling.querySelector('p.fsdocs-summary').textContent
  46.  
  47. const span = document.createElement('span')
  48. span.setAttribute('style', `font-size: 1rem;margin-bottom: 0.8rem;`)
  49. span.setAttribute('class', `hide toc-summary`)
  50. span.textContent = summary
  51.  
  52. divContainer.appendChild(clonedElem)
  53. divContainer.appendChild(span)
  54.  
  55. topNavAnchorLinksContainer.appendChild(divContainer)
  56. })

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址