diff --git a/lc-font-changer/lc-font-changer.user.js b/lc-font-changer/lc-font-changer.user.js new file mode 100644 index 0000000..6c8f5f5 --- /dev/null +++ b/lc-font-changer/lc-font-changer.user.js @@ -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() })); +})(); \ No newline at end of file