User:TwoBits/common.js

/* * @title			TOC toggle button. * @description		Adds a button to toggle the visibility of the Table of *					Contents (TOC). * @author			User:TwoBits * @licence			CC-BY-SA mw.hook('wikipage.content').add(function {   const toc = document.getElementById('mw-panel-toc'),          tocBtn = document.getElementById('vector-page-titlebar-toc'),          tocCheckbox = document.getElementById('vector-page-titlebar-toc-checkbox'),          navBarIcons = document.querySelector('.vector-sticky-header-icons'),          fragment = document.createDocumentFragment;

// Place TOC toggle button in the top navbar. fragment.appendChild(tocBtn); navBarIcons.prepend(fragment);

// Add tooltip and toggle TOC function to the button. tocBtn.setAttribute('title', 'Show/hide table of contents');

tocCheckbox.addEventListener('click', function {      toc.classList.toggle('is-visible');    }); });