User:Joeytwiddle: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Marti (talk | contribs)
m →‎Current techniques for loading library userscripts: Reply for JoeyTwiddle on running before other scripts in the page, etc.
Line 60: Line 60:


:I am also taking your "clearStyle" a few different ways... the main being overriding CSS inheritance... please correct me if I'm misunderstanding this.[[User:Marti|Marti]] 02:33, 8 August 2009 (EDT)
:I am also taking your "clearStyle" a few different ways... the main being overriding CSS inheritance... please correct me if I'm misunderstanding this.[[User:Marti|Marti]] 02:33, 8 August 2009 (EDT)
::You are correct I am wanting to override any inheritance.


= Suggestion: Track homepage of installed scripts (for docs, updates) =
= Suggestion: Track homepage of installed scripts (for docs, updates) =

Revision as of 00:37, 14 August 2009

I have various suggestions for Greasemonkey development below.

Suggestion: Immediate loading of an enabled script

When we bring up the monkey's menu to turn on a script which was un-checked (disabled), we then have to reload the page for the script to be executed. Why?! Since userscripts are not run until after the page has loaded, couldn't GM run the activated script immediately, without the need for a page refresh?

(You don't necessarily need a full Reload. Navigating to the current page via a link or by URLbar->Enter should be enough. However I tend to naturally hit Ctrl+R or the Reload icon, although in FF this causes a full reload which is significantly slower.)

Scripts which would benefit from this are those which we use more like a Bookmarklet. Some scripts can work over a large range of websites, but we usually prefer them disabled. Occasionally we want to use a script for one page, or for a short while during a browsing session. Sometimes with such scripts, the solution is for them to add a link or button to the page, and then lie dormant, only activating when the link or button is clicked.

Library Userscripts and Dependencies

Suggestion: @depends metadata

It could be useful to have an extra meta tag:

Template:Samp

The @depends meta would cause Greasemonkey to load the specified script from the user's gm_scripts/ subfolder before running the userscript which contained the meta.

This would allow us to define a library script of common functions which we can re-use in any of our userscripts, simply by adding the meta. These library scripts are always loaded from a trusted source, they are local userscripts which do nothing when run alone.

The @version of the target library scripts could be checked against the conditions defined by >= in @depends. The user or the update system could be informed if the requirements are not met.

Sounds like a good start to a feature request in case the sandbox isn't ever expanded... you may wish to enter an enhancement ticket at http://greasemonkey.devjavu.com/newticket with this instead of the wiki talk pages. It will get the proper attention there. Marti 04:46, 7 June 2009 (EDT)
Thanks Marti, I see that is where the development discussion is. The greasemonkey-dev mailing list is to be overwhelmed with user-like questions!
Aaron also contacted me last week while I was out at conference and the new ticket home is at http://github.com/greasemonkey/ Things are still not fully set up there and hopefully it will get the attention that your ideas and presentation deserve. Marti 02:02, 8 August 2009 (EDT)

Current techniques for loading library userscripts

It is already possible to use userscripts as libraries by a couple of techniques:

Pre-embed with GM

Have one userscript load early, and let it embed some new JS functions into the unsafeWindow. Later userscripts may check the window to see if the functions it wants to use are available.

Or create an Object full of useful functions, and embed it in the DOM. Any userscripts which execute later could reference the object to make use of those functions. Unfortunately this raises security issues since untrusted scripts can access that globally visible object too. (Maybe we can force our library to drop GM internals from our scope, using fn.toString() for example.) We would somehow need to ensure the library scripts run first, and that they run on all pages where one of their dependent scripts will run.

Load-on-demand via http

When we want to load a library and it is not already in the page. Add a new script element to the page, with src attribute pointing to a publically visible http URL where the library userscript is located. Whether the functions from the loaded script become immediately visible depends. It seems to work fine when done with Bookmarklets in Firefox3.5, but some other browsers may need to wait (via a setTimeout or scriptElement.onload) *before* the loaded functions will become visible to running code.

There may be other techniques...

Given that these techniques exist, does that mean we don't need @depends?

You will probably need to have some more chats with Johan (ecmanaut) and if Aaron continues to make himself more available, him as well. Anthony may also pop in every once in a while too. As I stated later in these replies, GM is a bit behind the times but still works... It is just harder to implement more advanced features from a heavily moderated and "silent" project. Best bet is to try the community that makes GM possible at userscripts.org. You can also read some of the communities responses at this topic Marti 02:45, 8 August 2009 (EDT)

Suggestion: GM_clearStyle()

It is common that you want your userscript to add some floating menus or windows on top of the page. Unfortunately these will often inherit CSS rules from the page, and your added elements can end up with strange colours and alignment. It would be handy to break out of page style settings and create elements using a default empty stylesheet. How might this be possible? Can we literally move to a fresh CSS namespace? Or do we need something like this?

Template:Samp

Part of my objectives with my involvement in GM is to educate (and be educated myself too) the other dev's into better implementations of existing methods. As you may have observed I don't always hit the right chord with everyone... however my dedication is still here. From my Mozilla experience it is possible to move to a separate namespace on the CSS however GM still needs some serious refactoring before this can happen. This unfortunately currently limits GM in several areas and is why several authors have forked GM.
I am also taking your "clearStyle" a few different ways... the main being overriding CSS inheritance... please correct me if I'm misunderstanding this.Marti 02:33, 8 August 2009 (EDT)
You are correct I am wanting to override any inheritance.

Suggestion: Track homepage of installed scripts (for docs, updates)

I often want to visit the homepage of a script I have installed, either for documentation, or for updates, but the author didn't include it. Not all userscripts are installed from userscripts.org, and even those that are can be difficult to find again. I would like Greasemonkey to make a record of the update URL and the homepage of a script when I install it. We could insert the meta tags if they were not included by the author, or inaccurate. There are update scripts which try to track scripts, but shouldn't it be supported?

Again I can't speak for everyone, but this would lead to some privacy concerns here. A few dev's have already stated it would be nice to drop the config.xml altogether in favor of some more favorable method... however no one has come up with a better idea as of yet. Oliver is working on a fork that may eventually address some of this but as of yet I have yet to see the proposed logic. Marti 02:28, 8 August 2009 (EDT)

Suggestion: What is Namespace good for? Drop it from the log!

Finally a thought on logging and @namespace. The only standard I have really seen @namespace used for is to provide the homepage of the script or the author in @namespace. Should this be officially declared as the intention of @namespace? And since these URLs are often long, does it really make sense to make them part of the headers of log messages? Wouldn't just the name of the script be more appropriate when reading the log?

See @namespace for different implementations of this. Part of metadata is for examination purposes and tracking both internally to GM and externally and everywhere in between. It is unlikely that it will be removed due to legal matters regarding metadata, but GM can surprise me every once in a while by ideas that aren't quite up to par. Marti 02:22, 8 August 2009 (EDT)

Contra Development

I'm actually quite happy that Greasemonkey has kept its API small, this can accommodate wider compatibility. I think any additions to the API should be discussed over time by developers and users. I was wondering whether the developers were intending to extend Greasemonkey in the future, or have decided to keep it small and tidy, and leave the addition of features (aka bloat) to other projects.

I can't speak for anyone else but I can report an observation and a link here. Ideas and suggestions are welcome by a certain portion of the community. I've noticed you've caught Johans eye and that is a plus for your contributions. I appreciate you working within the community and being objective enough to present your ideas in a professional manner. I can report also that Greasemonkey doesn't change a whole lot over time, but that is always subject to changing. The dev group (mailing list) is usually quite vacant but not all the time. I can tell you from first hand experience, they don't like "noise" as they put it. This constitutes asking too many questions when the primary authors are in a bad mood (no offense intended just an observation)... so use your best judgement and don't be afraid to ask other people such as the community that makes GM possible at http://userscripts.org. Marti 02:23, 8 August 2009 (EDT)

GrimeApe - an HTTP Proxy acting like Greasemonkey

I recently wrote an emulation of Greasemonkey in a proxy, so that userscripts would run in Konqueror. It's called GrimeApe and can be found at http://hwi.ath.cx/

Unfortunately I don't have a lot of time to check this out, but there is also a Konqueror 3.5 plugin that supports this, but as cross platform userscripting doesn't appear to the be focus of the GM wiki, I haven't added it yet. You might want to add it to Cross-browser userscripting and explain it a little more in detail. Make note the TOC is currently alphabetized. Marti 02:07, 8 August 2009 (EDT)