-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadthedocs.user.js
62 lines (56 loc) · 1.75 KB
/
readthedocs.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==UserScript==
// @name ReadTheDocs tweak
// @namespace https://github.com/lilydjwg/userscripts
// @description ReadTheDocs tweak
// @include https://*.readthedocs.io/*
// @include https://docs.ansible.com/*
// @version 0.2
// @run-at document-idle
// @grant none
// ==/UserScript==
(function() {
'use strict'
const may_hide = function(toggle) {
const content = document.querySelector('.wy-nav-content-wrap')
const nav = document.querySelector('nav')
const footer = document.querySelector('.rst-current-version')
let hide = sessionStorage.getItem('hide-nav') == 'true'
if(toggle) {
hide = !hide
sessionStorage.setItem('hide-nav', hide)
}
if(hide) {
content.style.marginLeft = '0'
// Some sites set this to calc(100% - 300px), e.g.
// https://docs.ansible.com/ansible/latest/user_guide/intro_getting_started.html
content.style.width = '100%'
nav.style.display = 'none'
// Some sites don't have footer, e.g.
// https://docs.ansible.com/ansible/latest/user_guide/intro_getting_started.html
if(footer) {
footer.style.display = 'none'
}
} else {
content.style.marginLeft = '300px'
content.style.width = ''
nav.style.display = 'block'
if(footer) {
footer.style.display = 'block'
}
}
}
const button = document.createElement('a')
button.textContent = 'Toggle Nav'
button.href = 'javascript: void(0)'
button.addEventListener('click', function() { may_hide(true) })
button.style.display = 'block'
button.style.position = 'fixed'
button.style.zIndex = '9999'
button.style.left = '1em'
button.style.top = '1em'
button.style.fontSize = '0.5em'
button.style.color = 'gray'
button.style.backgroundColor = 'white'
document.body.append(button)
may_hide()
})()