How to make an extension that does all of this?
Saturday, May 5, 2012 8:20:36 PM
2. The injected script should start
- on click of a button
- on keyboard shortcut
- on mouse gesture (optional, if the user wants to set up a gesture)
3. The extension should have
- an options page for the more complicated settings
- a help page for all people who need to read up what some of the settings could mean
- a popup for live settings
4. The popup should
- not open on the normal click that starts the injected script
- be able to change some preferences
5. The preferences' changes in the popup should be
- applied to page without the need to reload the page.
- saved to the extension's preferences, as soon as the popup closes (or live, if possible).
6. The preferences set in the options page or the popup should be applied even when the extension's injected script is started by keyboard or mouse gesture.
Content follows here, as soon as I have written it or, in case of the popup, solved the problems.
If you know how to do especially the popup live stuff, I would appreciate if you can point me to the URL where I can read it up or drop an example in the comments below.







Martin KadlecBS-Harou # Saturday, May 5, 2012 9:46:01 PM
QuHno # Saturday, May 5, 2012 10:09:02 PM
I use with an onchange listener and that would require a constant stream of messages to float between the popup and the page ...
Martin KadlecBS-Harou # Sunday, May 6, 2012 12:06:42 AM
Originally posted by QuHno:
The problem is that the extension/popup and the injected script run asynchronous. So there is no direct way to access one from the other. As far as I know the messages are the only way.
QuHno # Sunday, May 6, 2012 9:23:06 AM
The second problem is, assuming it is a script that should run on every page and not using the @include rules, that the injected scripts are injected to every page even if it is not necessary.
Some scripts only need to be injected if and when the button is clicked. If I imagine some users who always have 200+ tabs open at the same time (yes, I know at least 2 people who do that) and then for example look at my cleanPages extension with about 90KB of injected script alone (not counted the needed space that has to be allocated for all the variables that are used internally - for example a complete copy of BODY, several DOM nodes for processing, some arrays etc.), this costs a huge amount of extra memory in total, with some pages this could sum up to several megabytes per page. OK, that can be mitigated by starting the main script part onmessage or onkeydown, but still the space has to be allocated, even if it is not used ...
Martin KadlecBS-Harou # Sunday, May 6, 2012 10:44:52 AM
QuHno # Sunday, May 6, 2012 11:43:43 AM
... and it would make it impossible to start the extension with a mouse gesture or a keyboard shortcut.
The memory footprint problem was meant more as a description of a general problem, not only of my extension. I just took my extension as an example because with that I really know how big it is
edit:
is it possible to set a onkeydown listener in the background script that sends the start message to the injected script of the tab in focus? (not by adding it to the button because I have built in an option to hide it)
Martin KadlecBS-Harou # Sunday, May 6, 2012 2:07:24 PM
Originally posted by QuHno:
No, because key-events work only on "selected/focused" page. BG process is never selected. That's why it is called background process
Originally posted by QuHno:
Yes and no ... You should not stop using something just because somebody told you so. There are cases when eval is actually good. You just have to use it wisely.
Originally posted by QuHno:
You can have small injected script that checks key events and gestures and then loads the big scripts from bg process