Skip to content

Instantly share code, notes, and snippets.

@devadathanmb
Last active September 9, 2023 09:49
Show Gist options
  • Save devadathanmb/a9fef55217a7919c53a6f56e2d74e534 to your computer and use it in GitHub Desktop.
Save devadathanmb/a9fef55217a7919c53a6f56e2d74e534 to your computer and use it in GitHub Desktop.
Leetcode change font
// ==UserScript==
// @name Change LeetCode Font
// @namespace http://yourwebsite.com
// @version 1.0
// @description Change the font in LeetCode code editor to JetBrains Mono Nerd Font
// @match https://leetcode.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Define your desired font
var desiredFont = "JetBrainsMono Nerd Font, monospace";
// Function to update the font for code editor elements
function updateFont() {
var codeEditorElements = document.querySelectorAll('.view-lines.monaco-mouse-cursor-text');
var marginElements = document.querySelectorAll(".margin-view-overlays");
codeEditorElements.forEach(function(element) {
element.style.fontFamily = desiredFont;
});
marginElements.forEach(function(element) {
element.style.fontFamily = desiredFont;
});
}
// Mutation Observer to detect changes in the page
var observer = new MutationObserver(function(mutationsList, observer) {
for (var mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
// A style attribute has changed, so update the font
updateFont();
}
}
});
// Observe changes in the document
observer.observe(document.body, { attributes: true, subtree: true });
// Update the font when the page initially loads
window.addEventListener('load', updateFont);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment