Is it possible to set config settings on Firefox from a Addon - firefox

I'm looking for a way to print from web without prompting the print dialog (I just made the question).
I found This method for Firefox and it seems to work, but it obviously will affect all websites. So I'm thinking of developing a Firefox Addon that makes this configuration to affect only specific websites.
I don't know nothing about building Firefox addons, but if it's possible to change settings this way I will learn how to do it.
So my question is.. Is it possible to set config settings on Firefox from a Addon and for specific websites?
Thanks a lot.

If you are going to develop a Firefox addon you could "easily" replace the print button and delegate to the standard print action on normal websites. For a list of URLs, i.e. your web site, you temporarily set print.always_print_silent to true and be done with it.
For modifying a preference in an addon you would something like this:
// Get the "accessibility." branch
var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService).getBranch("accessibility.");
// prefs is an nsIPrefBranch.
// Look in the above section for examples of getting one.
var value = prefs.getBoolPref("typeaheadfind");
// get a pref (accessibility.typeaheadfind)
prefs.setBoolPref("typeaheadfind", !value); // set a pref (accessibility.typeaheadfind)
(taken from this snippet).

One way is to provide your own implementation of the printing prompt service. You could then inspect the window being printed and turn on silent printing if you want to bypass the print dialog. You might need to retrieve the original service to handle the cases that you don't want to. I couldn't find much documentation but there's some related documentation here.

Related

Is there a way to change about:config DOM value for only one website in firefox

I would like to allow one website to use the window.resizeTo(); function but disallow all the other websites from doing that... I wonder if there is any way to do that even if its difficult.
even if its not in the firefox original settings maybe there is an addon that will allow for it??
You can create a file called user.js in your profile directory. Most Firefox preferences are kept in a file called prefs.js - but the browser can write to this file, and often overwrite any changes.
If user.js can accept if-else logic and access the current URL, you could very easily establish logic to turn preferences on and off depending upon the URL.
I found this information here.
Update
As far as I can see, user.js is only read when the browser loads - so the method described above won't work :( The best way to achieve required functionality would be to use/write/invent a Firefox addon.
It doesn't appear that the about:config preferences are that granular. You can either set a preference value to true for the entire browser, or false for the entire browser. But you cannot define case-by-case values.
Source: http://kb.mozillazine.org/Firefox...config_Entries#DOM.
This limitation is illustrated through the options of the browser as well (all or none):

how to enable Safari Extensions when using a web view

I am using a Web view in my application, instead of open a Safari browser instance, so I noticed that Safari extensions doesn't work. Is there a possibility to enable this feature when using a custom web view in a Cocoa Application?
The reason by which I need to use Safari extensions is to inject javascript to whatever web page is loaded at one moment, so if is there another approach to do it without using extensions, welcome any suggestions or samples.
There's no way to use Safari extensions in a web view.
If your script isn't too big, how about formatting it as a "javascript:" bookmarklet and setting the web view's location to it?
[Edit: Stuff below added in response to questioner's request for "a bit more about that technique".]
Say you want to change the background color of the page to yellow and all the text to red. The javascript to do that would be something like:
document.body.style.backgroundColor = "yellow";
document.body.style.color = "red !important";
To turn the script into a bookmarklet, you just:
Wrap it in an anonymous function,
remove all line breaks,
(optionally) remove any unnecessary spaces,
url-encode it,
and prefix the whole thing with "javascript:".
So, the example would become:
javascript:(function(){document.body.style.backgroundColor%3D%22yellow%22%3B%0Adocument.body.style.color%3D%22red%20!important%22%3B%0A}());
Then you can set the webview's window.location to that string to "run" the bookmarklet.
Here is a page with an automatic script to bookmarklet converter that seems to work.

Firefox Extension - Monitor refresh and change of tab

I need to know when a user refreshs the page and when he switches to another tab.
Does anyone has a clue how to capture this in a firefox extension?
Best regards
Christian
What you seem to want is knowing when the value in the location bar changes. This requires implementing nsIWebProgressListener interface. The only method you really need is onLocationChange, rest of them should be dummies. You can find the documentation along with code examples here: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners. You can also use progress listeners to monitor page loads.

Functionality like "about:whatever" to display arbitrary data in Firefox

I'm writing a Greasemonkey script that has a fair few user settings (just using GM_getValue and GM_setValue).
What I'd like to be able to do is create a settings page for the script, and add that to the #include-d sites. So, for example, it'd run on:
#include http://www.greasemonkeyedsite.com/*
#include about:myScriptConfig
Then the script would check the URL of the site it's being called for. If it's the about: one it'd create and display a settings page, otherwise it'd just run the script as usual.
I came up with this under the impression that you could type about:(anything) and it'd show up fine, with just the text following the about: as the page content. I remember this working last time I checked it, but that was years ago.
Seems to be that you can't just display arbitrary data by use of about:x any more, though. Firefox just displays a "The URL is not valid and cannot be loaded" error.
I know about the data: URI protocol, but it's not suitable as entering it manually into the address bar doesn't lead to its own page.
Is there some equivalent behaviour? Or am I going to have to just have a "settings" button on the top corner of greasemonkeyedsite.com that hides and shows a settings div?
If you have a permanent web site, you could make a URL there that becomes the Greasemonkey script's settings page. That could even be a convenient URL that allows the user to download the script if he does not already have it installed, and you can, that way, also offer the user a software update when a new version of your script is released. (Just have the Greasemonkey script check some "current version" part of the settings page.)
As mentioned by jnpcl, it is possible to create a chrome:// URI within the browser, but as I understand it, that requires a full-fledged Firefox add-on rather than just a Greasemonkey script.
You could use a designated URL on the affected site if you do not have a permanent web site, like http://www.greasemonekyedsite.com/myGreasemonkeySettingsPage. Your script could then strip out the parts of their 404 page it does not need, and then it could insert its list of settings within.

Automating Firefox configuration settings

During web development work, I need to be able to quickly switch various config settings in Firefox. In particular I need to be able to:
1) Switch off cookies
2) Switch off javascript
3) Switch my user agent (I have the user-agent switcher add-on installed)
and then back again.
Instead of doing this manually, it would be great if i could add a "macro" button to my toolbar that I could simply click to toggle the three settings above.
Anyone know if this is possible?
Btw - Firefox Profiles doesn't really cut it. You can't dynamically switch profiles within a specific Firefox instance, which I need to be able to do.
Btw2 - I got excited when i saw Greasemonkey, Chicken Foot, but it looks like these can only automate browsing/DOM tasks, and not with firefox configuration settings.
Thanks Richard.
Because of your requirements, it'd probably best for you to make a simple add-on yourself. You could even have it add a button that goes back and forth between things.
You can disable cookies by setting the preference "network.cookie.cookieBehavior" to 2, you can turn off JavaScript by setting the preference "javascript.enabled" to false, and you can modify the user agent by changing the preference "general.useragent.extra.firefox".
To do these things, you'll need to use the preference API, which is documented here.
There are other add-ons that I think will get all the functionality you're looking for (albeit, not all in one tool).
https://addons.mozilla.org/en-US/firefox/addon/2497
https://addons.mozilla.org/en-US/firefox/addon/6527
https://addons.mozilla.org/en-US/firefox/addon/59
If you wanted to extend the functionality of any of these Add-ons, XPI files are just .zip files with a different extension. You can rename them and unpack them and find out how they do what they do, extending them, install your own customized version, etc.
The web-developer toolbar will do all the things you requested except switching the user-agent string, which can be accomplished through the UA switcher addon you already use. However it can't be macroed as far as I know, but it can be accomplished with a few mouse click.
Try iMacros.
From their site:
"Whatever you do with Firefox, iMacros can automate it."

Resources