Fsharp library docs - easy skim TOC

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

  1. // ==UserScript==
  2. // @name Fsharp library docs - easy skim TOC
  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. // @match https://fsprojects.github.io/FSharp.Control.AsyncSeq/reference/*
  9. // @grant GM_addStyle
  10. // @version 1.2
  11. // @author -
  12. // @description 13/04/2022, 2:14:00 pm
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. GM_addStyle(`.hide {display:none;}`)
  17.  
  18. const button = document.createElement('button')
  19. button.setAttribute('style', `display: block;margin-bottom: 0.8rem; margin-top: 0.8rem;`)
  20. button.textContent = 'Show Summaries'
  21.  
  22. button.onclick = () => {
  23. Array.from(document.querySelectorAll('.toc-summary')).forEach(elem => {
  24. elem.classList.toggle('hide')
  25. })
  26. }
  27.  
  28. const apiAnchorLinks = Array.from(document.querySelectorAll('.fsdocs-member-usage code a[href^="#"]'))
  29.  
  30. const topNavAnchorLinksContainer = document.createElement('div')
  31. topNavAnchorLinksContainer.setAttribute('class', 'anchor-nav-container')
  32. topNavAnchorLinksContainer.setAttribute('style', 'display:inline-flex;flex-direction:column;')
  33.  
  34. document.querySelector('.fsdocs-xmldoc').insertAdjacentElement('afterend', topNavAnchorLinksContainer)
  35. document.querySelector('#content>div').insertBefore(button, document.querySelector('.anchor-nav-container'))
  36.  
  37. apiAnchorLinks.forEach(elem => {
  38.  
  39. const clonedElem = elem.cloneNode(true)
  40. clonedElem.querySelector('code span>span')?.remove()
  41.  
  42. const divContainer = document.createElement('div')
  43. divContainer.setAttribute('style', `display: flex;flex-direction: column;`)
  44.  
  45.  
  46. const summary = elem.closest('.fsdocs-member-usage').nextElementSibling.querySelector('p.fsdocs-summary').textContent
  47.  
  48. const span = document.createElement('span')
  49. span.setAttribute('style', `font-size: 1rem;margin-bottom: 0.8rem;`)
  50. span.setAttribute('class', `hide toc-summary`)
  51. span.textContent = summary
  52.  
  53. divContainer.appendChild(clonedElem)
  54. divContainer.appendChild(span)
  55.  
  56. topNavAnchorLinksContainer.appendChild(divContainer)
  57. })
  58.  
  59.  
  60. document.querySelector("#navbarsExampleDefault>a").href = "https://fsharp.github.io/fsharp-core-docs/"
  61.  
  62.  
  63.  
  64.