Clean TypeScript handbook

Make reading TypeScript documentation better on vertical monitor

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Clean TypeScript handbook
// @namespace    http://kuntau.org
// @version      0.1
// @description  Make reading TypeScript documentation better on vertical monitor
// @author       Kuntau
// @match        https://www.typescriptlang.org/docs/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=typescriptlang.org
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
  'use strict';

  const checkElmExistTimer = setInterval(function() {
    let topMenuSelector = "top-menu"

    // check our custom button
    if (document.getElementsByClassName("custom-btn").length === 0) {
      const topMenu = document.getElementById(topMenuSelector)
      if (topMenu) {
        addButton(topMenu)
      }
    }
  }, 5000)

  function addButton(Node) {
    const btnSidebar = createButton("☰", "Show/hide sidebar")
    const btnTOC = createButton("☲", "Show/hide table of content")
    const elm = document.createElement("div")

    let sidebarStatus = true
    let tocStatus = true

    elm.style.display = "flex"
    elm.appendChild(btnSidebar)
    elm.appendChild(btnTOC)

    btnSidebar.onclick = function() {
      sidebarStatus = !sidebarStatus
      hideSidebar(sidebarStatus)
    }

    btnTOC.onclick = function() {
      tocStatus = !tocStatus
      hideTOC(tocStatus)
    }

    // Node.style.justifyContent = "flex-start"
    Node.append(elm)
  }

  function createButton(icon, title) {
    const btn = document.createElement("button")
    btn.innerHTML = icon
    btn.setAttribute('class', 'custom-btn')
    btn.setAttribute('title', title)

    return btn
  }

  function hideSidebar(status) {
    const sidebar = document.getElementById("sidebar")
    if (status) {
      sidebar.style.display = "block"
    } else {
      sidebar.style.display = "none"
    }
  }

  function hideTOC(status) {
    const toc = document.getElementsByClassName("handbook-toc")
    if (status) {
      toc[0].style.display = "block"
    } else {
      toc[0].style.display = "none"
    }
  }

})();