Add removepref excmd

This commit is contained in:
Oliver Blanthorn 2019-10-10 20:16:59 +01:00
parent fd7f7f218a
commit 647d3221a9
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 26 additions and 1 deletions

View file

@ -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.
*

View file

@ -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 {