-
-
Save mino0123/17b0b1ef8c323baeb9e41219ab95f311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Qiita_TOC_to_content | |
// @namespace mino0123 | |
// @include http://qiita.com/*/items/* | |
// @include http://qiita.com/*/private/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
const subColumnEl = document.getElementsByClassName('col-sm-3')[0]; | |
if (subColumnEl) { | |
const observer = new MutationObserver((mutations) => { | |
const tocTreeEl = document.getElementsByClassName('tocTree')[0]; | |
const contentEl = document.querySelector('.markdownContent.clearfix');// avoid slide | |
const hasTocItem = tocTreeEl.getElementsByTagName('li').length > 0; | |
if (tocTreeEl && contentEl && hasTocItem) { | |
// Disconnect observer | |
observer.disconnect(); | |
// Copy toc to content | |
const cloneToc = tocTreeEl.cloneNode(true); | |
cloneToc.className += ' tocToContent'; | |
contentEl.insertBefore(cloneToc, contentEl.firstChild); | |
// Add styles | |
const styleEl = document.createElement('style'); | |
styleEl.type = 'text/css'; | |
styleEl.innerHTML = ` | |
.tocToContent { | |
width: 100% !important; | |
border: 1px solid #CCC; | |
font-size: 70%; | |
} | |
.tocToContent a { | |
display: inline !important; | |
} | |
`; | |
document.head.appendChild(styleEl); | |
} | |
}); | |
observer.observe(subColumnEl, { childList: true, subtree: true }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment