Skip to content

Instantly share code, notes, and snippets.

@vuboi
Created November 6, 2024 02:03
Show Gist options
  • Save vuboi/5133610959410f3e6056cb50f3936f65 to your computer and use it in GitHub Desktop.
Save vuboi/5133610959410f3e6056cb50f3936f65 to your computer and use it in GitHub Desktop.
vscode_custom
document.addEventListener('DOMContentLoaded', function() {
const checkElement = setInterval(() => {
const commandDialog = document.querySelector(".quick-input-widget");
if (commandDialog) {
// Check if the command palette element is visible for the first time.
if (commandDialog.style.display !== "none") {
applyBlur();
}
observeCommandDialog(commandDialog);
clearInterval(checkElement);
}
}, 500); // Check every 0.5s
function observeCommandDialog(commandDialog) {
const observer = new MutationObserver(() => {
if (commandDialog.style.display !== "none") {
applyBlur();
} else {
removeBlur();
}
});
observer.observe(commandDialog, { attributes: true });
}
function applyBlur() {
const targetDiv = document.querySelector(".monaco-workbench .part.editor>.content");
let blurElement = document.getElementById("bg-blur");
if (!blurElement) {
blurElement = document.createElement("div");
blurElement.setAttribute('id', 'bg-blur');
blurElement.addEventListener('click', removeBlur);
targetDiv.appendChild(blurElement);
}
}
function removeBlur() {
const blurElement = document.getElementById("bg-blur");
if (blurElement) {
blurElement.remove();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment