New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose (version) information to user scripts #1452
Comments
I'd love this very much. Being able to have my own update method for users not yet using GM with autoupdating script would be amazing. But also having a way to be able to do an update if the sourceurl isn't yet know would be amazing. Something like: if (gmVersion < 0.9.13) { |
I'm thinking there's a much larger overall hole to be filled. We can provide information about the platform (greasemonkey itself) and the script (its own metadata). The latter is especially useful for an @require, to know the info of whatever script it is included in. So e.g. the platform version would be in there, and the script's downloadURL (perhaps, exact details will need to be figured out). Or if we're gonna do it, let's really do it. |
The branch already merged from #1053 did something like this, but I didn't keep it in the merge because I wasn't totally comfortable with exactly the way it was implemented.Care to elaborate? |
Mostly because it seemed a little haphazard, and I was hoping we could do something like this instead. |
Spitballing what this might look like. In the sandbox:
The What about the formatting? Should it be What else does Greasemonkey know that a script might want? |
Like the look of the proposed functionality. willUpdate should be very useful. Edit: Oops. So I guess modifying my previous example it'd be: var numVersion = GM_info.version() * 1; //convert from string Would that be about right? If so, everything looks good to me. I'm undecided on the metadata.xxx block I like the cleanliness of script.version, but if there's a lot of metadata, I guess the metadata block makes more sense from an organisational standpoint. |
Was the first line of data there in my proposed example above. |
+1 on exposing GM's parsed view of the script's metadata to the script itself – that makes stuff more DRY. Good syntax. What I'd add is (not necessarily as properties on { "name": ["Example User Script"] , "include": [ "http://www.example.com/*" , "http://www.example.org/*" ] , "exclude": ["http://www.example.com/login*"] , "version": ["1.0"] , ... other script headers GM might or might not support here ... } The use case would be to allow script and library authors to prototype useful GM headers, so we can present viable ways for people to showcase stuff in @require libraries that, if they turn out popular and well merited, might be considered for GM proper. We have had huge threads on that kind of thing on GM-dev for proposals like @xpath and other meta things, largely because we have no way to improve GM without changing its core today. |
For that sort of usage, it would seem best to me to simply expose the string between the ==UserScript== bits, and let scripts deal with parsing it from there, in whatever way they elect to use it beyond the documented behavior. |
If we API it we could easily support either, though I doubt the string version would get as much use. What's good about the two proposals above are their no-fuss webbiness for the common use case. |
and let scripts deal with parsing it from thereIf the whole point of offering them this value is so they can parse information out of it, why not parse it for them? |
I see no point in getting the raw ==UserScript== text when I am going to parse it anyways. It should be parse automatically by default. Perhaps a solution like this which could satisfy those who need the raw text?
|
Johan said "let's expose every parsed item!". I said "expose the string" (alongside the parsed, supported, items).
Because you know how to parse it. Because we can't possibly parse every possible type of item that anyone might ever make up in the future. A while back we would have just given name/value keypairs. Then we get things like To repeat: we can't know the right way to handle every possible thing anyone can make up. So we expose the info we already know (and use), structured. Then we give the whole string, so that those authors who might want to make up their own things can do so. |
To date, every I find it highly likely that 90%+ of all future header imperatives will be too, and that most users will want exactly that, as well. Some may use multiple white-space-separated values on that line, like We could do as @cletusc suggests above if we really care for the "whole string" part (I personally don't, but I wouldn't fight supporting it, especially not if someone wants it), but the important part to me would be an api which, for a header like // ==UserScript== // @name My extended script // @namespace https://someone.github.com/ // @description Cool things // @include http://google.com/* // @include https://google.com/* // @resource css styles.css // @require lib.js // @xpath img_links //a[@href][.//img[@src]] // @unwrap // ==/UserScript== returns this easy-to-consume object: { "name": ["My extended script"] , "namespace": ["https://someone.github.com/"] , "description": ["Cool things"] , "include": [ "http://google.com/*" , "https://google.com/*" ] , "resource": ["css styles.css"] , "require": ["lib.js"] , "xpath": ["img_links //a[@href][.//img[@src]]"] , "unwrap": [null] } ( |
Huh. I never noticed "scriptMetaStr" in your original proposal. To me it feels a little out of place in the proposed |
I edited that in and, upon re-reading comment history, see that I forgot to mention it. |
Seems like I'm in the minority. Can someone championing full-raw-parsed-data provide an entire sample GM_info object as a literal, like I did above? Does it still have both versions of the metadata? How are they organized? |
That's what my example in #1452 (comment) was. It'd just be another |
@johan // ==UserScript== // @name My extended script // @namespace https://someone.github.com/ // @description Cool things // @include http://google.com/* // @include https://google.com/* // @resource css styles.css // @resource othercss otherstyles.css // @require lib.js // @xpath img_links //a[@href][.//img[@src]] // @unwrap // ==/UserScript== { "name": ["My", "extended", "script"], "namespace": ["https://someone.github.com/"], "description": ["Cool", "things"], "include": ["http://google.com/*", "https://google.com/*"], "resource": [ ["css", "styles.css"], ["othercss", "otherstyles.css"] ], "require": ["lib.js"], "xpath": [ ["img_links", "//a[@href][.//img[@src]]"] ], "unwrap": [null] } Basically, the text proceeded by the "@" sign becomes the key and any text that follows until a new line is broken up into an array with space as a delimiter. That array (unless there is only a single value on a line then just the string is used) is then put in the array for each key so that more than one value for each key can be saved (this is the same behavior as Johan's example). I'm not sure if I explained that well enough but hopefully the example above speaks for itself. This parse method works universally and no data is lost. To get the whole value of |
@sizzlemctwizzle Just to clarify, I am voting for having both my My championed |
Scripts consuming these half-parsed Hence "half-parsed", in my notes above. I'm looking for the best compromise between hackable and can-do-everything, and I believe "hackable" is the most important part. |
I see your point with the
Yes it is. We don't want to force constraints upon people if it isn't absolutely necessary. |
I am a +1 for @johan's last entry.
would become
...where any user-defined keys would act like a If I decided to create a metadata entry that is delimited by spaces, I could easily parse just the keys I need and split by spaces. It is far easier parsing one key to meet my demands than it is parsing an entire block of text myself and possibly goofing. Now whether or not this is used in a global |
I think we present the same idea, except maybe this part:
In the half-parsed Both |
Gotcha, I agree with you on doing it that way then. Just as long as there is some way to get what GM is using for the strict items. |
Any code forthcoming for these proposals? |
I've taken a very shallow stab at this. To note:
|
If the script contains a key, regardless of what it is, it should be shown in the "script" portion. |
Nobody's contributed code yet. So I'm going to split "structured" data out of this issue and resolve this with what I've already written, which for reference produces e.g.:
Because it should be easy to add more in the future, but there isn't clear agreement yet what it should be or how it should work. As written (and this is easy to explain in documentation) these are the values Greasemonkey actually uses (minus user 'cludes -- should we add them?), in |
There should be a way for existing "userland" update scripts to know that they're running in a version of Greasemonkey that does updates itself, and skip running. In order for this to be useful, they should also know whether updates are running.
The branch already merged from #1053 did something like this, but I didn't keep it in the merge because I wasn't totally comfortable with exactly the way it was implemented. I always meant to revisit. This issue is to track that this happens.
The text was updated successfully, but these errors were encountered: