diff --git a/src/excmds.ts b/src/excmds.ts index 6de230d9..8cfb23e7 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -491,13 +491,23 @@ export async function colourscheme(themename: string) { * Note that not all of the keys Firefox uses are suggested by Tridactyl. * * e.g.: `setpref general.warnOnAboutConfig false` - * `setpref extensions.webextensions.restricterDomains ""` */ //#background export function setpref(key: string, ...value: string[]) { return Native.writePref(key, value.join(" ")) } +/** + * Remove a setting from your user.js file. + * + * @param key The key that should be set. Must not be quoted. Must not contain spaces. + * + */ +//#background +export function removepref(key: string) { + return Native.removePref(key) +} + /** * Like [[fixamo]] but quieter. * diff --git a/src/lib/native.ts b/src/lib/native.ts index 8fc94f7a..51295a36 100644 --- a/src/lib/native.ts +++ b/src/lib/native.ts @@ -758,6 +758,21 @@ export async function writePref(name: string, value: any) { } } +/** Removes a preference from user.js */ +export async function removePref(name: string) { + const file = (await getProfileDir()) + "/user.js" + // No need to check the return code because read returns "" when failing to + // read a file + const text = (await read(file)).content + const prefPos = text.indexOf(`user_pref("${name}",`) + if (prefPos >= 0) { + let substr = text.substring(prefPos) + const prefEnd = substr.indexOf(";\n") + 1 + substr = text.substring(prefPos, prefPos + prefEnd) + write(file, text.replace(substr, ``)) + } +} + /** Obey Mozilla's orders https://github.com/tridactyl/tridactyl/issues/1800 */ export async function unfixamo() { try {