HTML, CSS, JS and other unsorted stuff

How to make an extension that does all of this?

, ,

1. The extension should do something with a webpage by the means of an injected script.

2. The injected script should start
  1. on click of a button
  2. on keyboard shortcut
  3. on mouse gesture (optional, if the user wants to set up a gesture)


3. The extension should have
  1. an options page for the more complicated settings
  2. a help page for all people who need to read up what some of the settings could mean
  3. a popup for live settings


4. The popup should
  1. not open on the normal click that starts the injected script
  2. be able to change some preferences


5. The preferences' changes in the popup should be
  1. applied to page without the need to reload the page.
  2. 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.

cleanPages mobile - very experimentalSome Opera Icons

Comments

Martin KadlecBS-Harou Saturday, May 5, 2012 9:46:01 PM

QuHno Saturday, May 5, 2012 10:09:02 PM

... but it is clumsy.
I use
<input type="range"
with an onchange listener and that would require a constant stream of messages to float between the popup and the page ... awww

Martin KadlecBS-Harou Sunday, May 6, 2012 12:06:42 AM

Originally posted by QuHno:

with an onchange listener and that would require a constant stream of messages to float between the popup and the page ...


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

Yes, I know.
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

perhaps, you could send the script as string in a message and run it with eval?

QuHno Sunday, May 6, 2012 11:43:43 AM

I could, but eval is evil devil

... 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 wink

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:

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)



No, because key-events work only on "selected/focused" page. BG process is never selected. That's why it is called background process p

Originally posted by QuHno:

I could, but eval is evil


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:

... and it would make it impossible to start the extension with a mouse gesture or a keyboard shortcut.


You can have small injected script that checks key events and gestures and then loads the big scripts from bg process smile

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies