-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-vscode-script.js
More file actions
66 lines (57 loc) · 2.07 KB
/
custom-vscode-script.js
File metadata and controls
66 lines (57 loc) · 2.07 KB
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
document.addEventListener('DOMContentLoaded', function () {
const checkElement = setInterval(() => {
const commandDialog = document.querySelector('.quick-input-widget')
if (commandDialog) {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (
mutation.type === 'attributes' &&
mutation.attributeName === 'style'
) {
if (commandDialog.style.display === 'none') {
handleEscape()
} else {
runMyScript()
}
}
})
})
observer.observe(commandDialog, { attributes: true })
clearInterval(checkElement)
} else {
console.log('Command dialog not found yet. Retrying...')
}
}, 500)
document.addEventListener(
'keydown',
function (event) {
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'p') {
event.preventDefault()
setTimeout(runMyScript, 50) // Adding a small delay
} else if (event.key === 'Escape' || event.key === 'Esc') {
event.preventDefault()
handleEscape()
}
},
true
)
function runMyScript() {
const targetDiv = document.querySelector('.monaco-workbench')
const existingElement = document.getElementById('command-blur')
if (existingElement) {
existingElement.remove()
}
const newElement = document.createElement('div')
newElement.setAttribute('id', 'command-blur')
newElement.addEventListener('click', function () {
newElement.remove()
})
targetDiv.appendChild(newElement)
}
function handleEscape() {
const element = document.getElementById('command-blur')
if (element) {
element.remove()
}
}
})