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
Add import userscript from file #2804
Conversation
50c0f3e
to
39efdc0
Compare
be1b004
to
a0a1058
Compare
Extract this zip file: icon.zip Pick import, browse to that
After a couple seconds, a broken editor with no script pops up. Nothing was installed. I believe this will happen for any relative resource reference, this one is an |
How would a WebExtension have access to these files in order to import them? I suppose you could import the entire |
Alternatively, are you just pointing out the point that the editor pops open and shouldn't? That is fixable. As for actually getting that script to install, I'm not sure. |
Try e.g. https://arantius.com/misc/greasemonkey/protect-textarea.user.js which contains the line
More generally that the error condition is not handled (because it's not even detected?). And predicting the users that will see exactly the feature they want, except it doesn't work in the case they want to use it for. |
Ah, okay. I must have missed that functionality. Cool.
Detecting the error is doable. Of course getting the resources from the disk is probably a no-go. However, getting them remotely may be possible. Of course the implicit downloadUrl set due to navigation / remote install won't be applied from a local install, but it might be possible to modify |
0cf4e56
to
7723b60
Compare
Added an error if the URL cannot be resolved to a full path (with notification). If |
fa23eb0
to
c1f8227
Compare
event.stopPropagation(); | ||
event.stopImmediatePropagation(); | ||
} | ||
document.getElementById('import-script-file') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The element with this ID is hidden by CSS, so is not clickable, so this code doesn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed clickable. Otherwise the installation page would never open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I check out this branch I see:
The <a href="#import-user-script" ...> and its text, but no <input>. Clicking the (visible) anchor does nothing. The CSS sets <input> opacity to zero so maybe it's supposed to be overlaid (towards what end?), but that's broken. If remove the opacity setting:
The position is off? Like I said above, the half-this-half-that implementation is suboptimal. I was indeed not clicking on it/it was invisible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, must have to do with the recent fixes to the MM styling. When I tested it just happen to be in the right location to work.
(towards what end?),
I thought this was obvious. You can't style input fields. So either you hide it and overlay it on text you would like to display or you're stuck with a "browse" button with absolutely no context. Now, I can grant you that at this moment in time the file picker is unnecessary, since they don't work (RIP Mozilla please). But down the line, unless you want to stick with the poor UI of a file input, the overlay is pretty much required.
Either way, I'll remove the boilerplate as it's, as you said, not needed at the time.
@@ -77,6 +118,9 @@ window.parseUserScript = function(content, url, failIfMissing) { | |||
case 'noframes': | |||
details.noFrames = true; | |||
break; | |||
case 'downloadURL': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a very intentional decision to not handle downloadURL, updateURL, etc. in GM4. I won't merge code that tries to add them again.
This causes a situation that breaks the principle of least astonishment. I might choose to save a script to my own disk/server, perhaps to isolate it from the original author. But then by accident through one little setting it downloads/updates to some other remote resource that someone else controls? Do not want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you propose then? We can't get the resources from disk without the user explicitly asking to open a file. As far as I'm aware we can't even open a 'please select next file' picker. Even if we could, asking the user to select every resource is pretty bad UX. Granted, the resources aren't downloaded due to current limitations of installFromSource
but that should eventually be fixed.
So, should the script be imported without the external resources? (Yes, that's what happens now, but at least with the current PR the URLs are available and can be used to fetch resources).
Everything could be .zip
but that could be pretty extreme for just a single script.
Alternatively, I could make it so that the original request takes precedence over the @downloadURL
, that way if you're hosting it somewhere then resources will be fetched from your host, but if you're installing it by just importing the script it can still fetch remote resources using @downloadURL
.
Or do we just not support relative paths? Which will probably break a lot of compatibility, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should also say that some of the above also applies to the full DB import / export. Of course if you're importing an archive created by GM then you have access to everything as it was. However, if you import an archive exported from TM or VM then the only 'bits' that GM understands is the raw script file itself and the value-store (if importing from TM). The previously set, internal, downloadUrl
will be unavailable (non-existant) and we're stuck with not being able to fetch resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all scripts specify @downloadURL
, so users would be left with sometimes working sometimes not, even with this.
It would make plenty sense to me to allow: 1) .user.js
import, if no deps (or all fully-specified and currently downloadable remote refs) and also 2) .zip
import where there's exactly one .user.js
and relative-only references to deps otherwise in the zip.
There's also some way to select a directory with a file browser? I don't know what access you get to files in that directory though.
@@ -153,10 +159,26 @@ function onHashChange(event) { | |||
} | |||
|
|||
|
|||
// Import a new user script | |||
// TODO: Add onImportUserScript to monkey menu when file picker bugs are fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it counterproductive and confusing to have this whole thing written half in one style and half in another. I'm also not keen on the awkward wording in the UI.
Write it so that it works well, now, complete. If and only if in the (distant, if ever) future something different becomes possible, then and only then write code to do that.
I'm going to close this and open a new one, branching from the initial commit. The new PR will focus on I'm also going to work on my import / export DB branch to follow the same ruleset as above. If an importing script doesn't have fully qualified resource paths then it won't be imported (unless the archive contains the GM 'bits'). |
Addresses #2612.
Not as nice as being able to navigate to the file but the the baseline result is the same. Unfortunately due to Mozilla issues with the panel a new tab has to be opened. When the relevant bug is fixed the import code should be copy/pastable directly into the Monkey Menu (necessary elements are in place).
I also have another branch that deals with import/export of the entire database, but that's somewhat reliant on the value-store PR (well, it could be done without the PR, but it makes things a bit simpler).