user_pref()
in Mozilla Firefox user.js?I have tried using an if-else
statement, but the contents of the first if
statement is executed, even if the given condition is false
. The contents of the else
statement is ignored.
Example #1:
if ( false )
{
// This is executed even though the given condition is false in Mozilla Firefox user.js.
user_pref( 'browser.display.background_color', '#000000' );
}
else
{
// Unfortunately, this is not executed in Mozilla Firefox user.js.
user_pref( 'browser.display.background_color', '#FFFFFF' );
}
Additionally, I have also tried using a ternary
expression to conditionally change a user preference, but the expression is skipped entirely.
Example #2:
// This is not executed at all in Mozilla Firefox user.js.
user_pref( 'browser.display.background_color', ( 1 === 2 ? '#000000' : '#FFFFFF' ) );
Overall, I am trying to eventually find a way to change user_pref()
properties conditionally depending on the contents of window.location.href
.
Reference the documentation for Firefox's User.js
file. Nowhere does it claim that the file takes javascript or any other (Turing complete) programming language.
The file takes either comments or user_pref()
lines only.
So, conditional statements are not allowed.
However, since you are modifying styles in your example, you can accomplish the same thing with user style CSS and/or the Stylish add-on (recommended). There you can use some logic, based on the domain and/or URL.
For logic about other, non-style, prefs, you might be able to write an extension to do what you wish.