Add lc-font-changer

This commit is contained in:
x 2024-08-01 01:50:11 +00:00
parent dec55fd62b
commit f372e58b89
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
// ==UserScript==
// @name LC Font Changer
// @namespace http://tampermonkey.net/
// @version 2024-08-01
// @description Configure a custom font for Leetcode's code editor
// @author Sangeeth Sudheer
// @match https://leetcode.com/problems/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
// @grant unsafeWindow
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
(function() {
'use strict';
function waitForLoad(cb) {
if ((unsafeWindow.monaco?.editor?.getEditors?.()?.length ?? 0) > 0) {
console.log("Invoking callback");
cb();
} else {
setTimeout(() => waitForLoad(cb), 1000);
}
}
function getFontFamily() {
let savedValue = GM_getValue("fontFamily", null);
if (!savedValue) {
GM_setValue("fontFamily", "Courier");
savedValue = "Courier";
}
return savedValue;
}
waitForLoad(() => unsafeWindow.monaco.editor.getEditors()[0].updateOptions({ fontFamily: getFontFamily() }));
})();