-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlsp.js
144 lines (119 loc) · 3.35 KB
/
lsp.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function hide (el) {
el.style.display = 'none'
}
function show (el, display = 'block') {
el.style.display = display
}
function hideVisibility (el) {
el.style.visibility = 'hidden'
}
function showVisibility (el) {
el.style.visibility = 'visible'
}
function hideElements () {
[
'.col-content > .tsd-panel',
'.container-main .col-menu.menu-highlight',
'.container-main > .col-content > .tsd-sources',
'.tsd-page-title',
'.tsd-page-toolbar',
'.tsd-index-group',
'.tsd-hierarchy'
].forEach(selector => {
const els = document.querySelectorAll(selector)
if (!els) return
Array.from(els).forEach(it => {
hide(it)
})
})
const panelThs = document.querySelectorAll('.tsd-panel-group > h2')
panelThs.forEach(it => {
it.style.display = 'none'
})
const footerEl = [...document.querySelectorAll('body > .container')].pop()
footerEl.style.display = 'none'
const genEl = document.querySelector('.tsd-generator')
genEl.style.display = 'none'
// region hide all-of-other panels
const hashId = window.location.hash.replace('#', '')
if (!hashId) {
return
}
let targetSize = {}
const memberEls = document.querySelectorAll('.tsd-member')
memberEls.forEach(it => {
const anchorEl = it.children.item(0)
if (!anchorEl || anchorEl.tagName?.toLowerCase() !== 'a') {
console.error('[Error anchorEl]', it)
return
}
const memberKey = anchorEl.id.toLowerCase()
if (memberKey !== hashId.toLowerCase()) {
it.style.display = 'none'
} else {
it.style.position = 'fixed'
it.style.left = '0px'
it.style.top = '0px'
it.style.width = '100%'
it.style.zIndex = 999
it.style.marginTop = '0px'
// hide tsd-parameters
;[it.querySelector('.tsd-parameters'),
it.querySelector('.tsd-parameters-title'),
it.querySelector('.tsd-returns-title'),
it.querySelector('.tsd-type-parameters-title'),
it.querySelector('.tsd-type-parameters')
].forEach(it => it && hide(it))
// apply size of body
const { height } = it.getBoundingClientRect()
Object.assign(
document.body.style,
{
height: height + 'px',
overflow: 'hidden',
background: 'transparent'
}
)
// apply link top open in new panel
it.querySelectorAll('a').forEach(link => {
if (!link.href) return
link.setAttribute('target', '_blank')
})
targetSize.height = height
}
})
// endregion
return targetSize
}
function adjustElements () {
const panels = document.querySelectorAll('.tsd-panel')
Array.from(panels).forEach(it => {
it.style.boxShadow = 'none'
it.style.background = 'transparent'
})
const main = document.querySelector('.container-main .col-content')
main.style.width = 'auto'
}
// entry
(function () {
if (top !== this) {
hideVisibility(document.documentElement)
window.onmessage = (e) => {
if (e?.data === 'ready') {
try {
const targetSize = hideElements()
adjustElements()
top.postMessage(JSON.stringify({
type: 'size',
payload: targetSize
}), '*')
} catch (e) {
console.error('LSP:', e)
}
setTimeout(() => {
showVisibility(document.documentElement)
}, 50)
}
}
}
}())