minbrowser / min

A fast, minimal browser that protects your privacy
https://minbrowser.org/
Apache License 2.0
7.97k stars 705 forks source link

Feature Request: Adding a script manager, aka Tampermonkey... #803

Open OodavidsinoO opened 5 years ago

OodavidsinoO commented 5 years ago

It could solve most of feature-requesting problems. Coz there are lots of scripts inside Tampermonkey Script Base

PalmerAL commented 5 years ago

Interesting idea! It looks like these are just standard JS files, so they should mostly work in Min already. In order to fully support this, I think we would need to do two things:

MarkWahlsten commented 5 years ago

Big ol' upvote for this!

MarkWahlsten commented 5 years ago

@PalmerAL – For the most part there is probably already a userscript for nearly everything, but to really open up the flexibility to less JS-savvy folk, would some kind of 'userscript generator' in a similar vein to this example be possible down the track, although with a somewhat more user-friendly interface like this bookmarklet generator?

There could also be text or dropdown fields to specify a trigger (whether via keyboard or an item in the right-click menu), and radio buttons for whether you wanted it to be be applied globally (like pinterest) or option specific sites? Ticking 'specific sites' could then reveal a text input?

I also saw this; way too advanced for me to use (I have no idea if it's useful for min) but still some pretty good info to point to on how to create userscripts.

For most cases a basic zip upload button or text input to paste into would be a huge improvement to start with, but some kind of generator could open up a whole world of possibilities.

For example I had a go at using your Pinterest userscript* to retrofit a keyboard shortcut trigger to this heckin' useful PrintWhatYouLike bookmarklet with this thread as my starting point, but with little success, mainly due to having no idea what parts to keep and what has to change. Which is where the Mr Coles example with an input for just the important part of the js would be really useful

If the above (or anything like it) would be a lot of work, another thought was updating the min userscripts wiki with some links or a guide similar to this one or the SimonAlling one above.

*I am also in the process of replying to the Bookmark thread, thankyou for that userscript! It works great :)

PalmerAL commented 5 years ago

I suspect that if we attempted to make our own script generator, it would get messy really quickly; it's never going to be possible to include enough options to support every feature someone could want in a userscript, and if we did, we would essentially be making our own programming language. However, I do agree that it would be nice to make userscripts more approachable; there's a couple ways I think we could do that:

MarkWahlsten commented 4 years ago

@PalmerAL – good point!

That SimonAlling generator possibly is useful, but it's a bit beyond my skill level to even know how to install it, haha (sigh) :(

This is about where my skill-level is at: GreaseMonkeyScriptGenerator

I'm definitely on board with your ideas for making it more user-friendly, like the syntax support and shortcut function!

Were you looking to implement some kind of interface in Preferences?

Thanks!

PalmerAL commented 4 years ago

is there a lot involved in editing a bookmarklet to work as a userscript?

Depends I suppose, but not really. A bookmarklet is just some JS script with "javascript:" in front of it; when you click the bookmark, the browser runs the script in the page. A userscript is just the same script, with some comments at the beginning to indicate what sites it should run on and when. So to convert them, you most likely just need to do this: https://stackoverflow.com/a/6906329

An interface to manage your installed scripts would be nice, but I'm not sure it's worth the investment. If we supported the syntax, you could just save the script and put it in your userscripts folder, which I think isn't too bad.

PalmerAL commented 4 years ago

I've started working on this in #1033; with that PR, you can import a tampermonkey script, and it will obey the specified exclude, match, and include rules.

To fully support importing scripts, we would need to:

I think we could also add a command to the UI to run a script, so you could type something like !userscript in the address bar and then pick a script.

MarkWahlsten commented 4 years ago

@PalmerAL

I've started working on this in #1033; with that PR, you can import a tampermonkey script, and it will obey the specified exclude, match, and include rules.

Brilliant! Can't wait! Would these be obeyed in addition to the way Min currently does it (with the url or "global" in the .js file name), or is it replacing that method?

implement run-at - I think this should be fairly easy.

I think we could also add a command to the UI to run a script, so you could type something like !userscript in the address bar and then pick a script.

Would the ability to organise scripts with tags (like with bookmarks) be something that'd be possible down the track?

Also thanks for the bookmarklet to greasemonkey tips, would it be worth adding that and the bind script to keyboard shortcut template links to the Userscripts wiki?

Thanks for all your amazing work!

PalmerAL commented 4 years ago

Brilliant! Can't wait! Would these be obeyed in addition to the way Min currently does it (with the url or "global" in the .js file name), or is it replacing that method?

Currently, both methods work. I'd like to eventually get rid of the old method, but we don't really have a good way to notify people that their scripts need to be updated, and it might be easier to just support the old method indefinitely rather than having to build that.

If Min is based on Chromium, would this include @run-at context-menu too?

Not automatically, but we should be able to do that fairly easily.

If not, I suppose we could add our own hotkeys to scripts themselves by bolting this template onto them... is there anything to watch out for when trying to do that on an existing script?

That should work fine AFAIK.

To minimise typing, could the command be something shorter, like !run (or similar)?

Good idea! That would make the key sequence cmd+e (or whatever you set the command to) + r + enter + a couple letters of the userscript name + enter again. I think that's probably short enough? But if you want a single letter, you could use the JS solution in the script as well.

Would the ability to organise scripts with tags (like with bookmarks) be something that'd be possible down the track?

Maybe? I have a hard time imaging having enough userscripts installed that organizing them would be an issue (and if you're running them by searching for a name, organization shouldn't be an issue anyway). How many scripts do you have?

Also thanks for the bookmarklet to greasemonkey tips, would it be worth adding that and the bind script to keyboard shortcut template links to the Userscripts wiki?

That would make sense; it would probably better to write a Min-specific guide rather than just linking to those though.

Thanks for all your amazing work!

Thanks!

PalmerAL commented 4 years ago

!run command is done in df783a4bb880397e1ca64f5e9af11f4893bb8586.

MarkWahlsten commented 4 years ago

...and it might be easier to just support the old method indefinitely rather than having to build that.

Oh right yeah, good point

Not automatically, but we should be able to do that fairly easily.

Awesome! That'd be so useful.

Good idea! That would make the key sequence cmd+e (or whatever you set the command to) + r + enter + a couple letters of the userscript name + enter again. I think that's probably short enough?

Yeah that'd be way better – wow so quick! (Haha this is why I love open source)

How many scripts do you have?

Ah, good point. Truthfully – not many at the moment. That's mostly because I haven't had much luck finding userscripts for the specific things I've needed to do. Or I've only be able to find bookmarklets and would get lost down a rabbit-hole figuring out how to edit it (hence my earlier posts).

In this case I guess I attempted to anticipate a future use case that might not actually eventuate.

That would make sense; it would probably better to write a Min-specific guide rather than just linking to those though.

Totally! A min-specific guide would be ideal, I guess I'm thinking of the links as a stop-gap until then?

One of the main troubles I had to date was figuring out which parts of the script were triggers that needed to be replaced with the keyboard shortcut snippet, and where to add it in. Not much can be done about that except learning JS.

But to that end, I like the examples you've added to the wiki article. More of those would definitely go a long way towards learning the bits that are relevant to Min, and makes it a bit less daunting.

MarkWahlsten commented 4 years ago

This convo gave me an onboarding idea that might need its own thread, but just leaving this here before I forget it –

What about displaying a rotation of "pro tip" tidbits in the address bar?

PalmerAL commented 4 years ago

Yeah, I've thought about doing that before, and I think it could solve some of the issues of features not being discoverable. Having them be relevant and not annoying is really hard though - Firefox did almost this exact thing a while ago, and every time I've run across one of the suggestions, it's been annoying and unhelpful. If you make them less noticeable, it reduces the risk of them being annoying, but then they don't get read as much either.

Some more guidance in the command interface probably would be good though, regardless of whether they're "tips" or something else.

A new thread would probably be good.

MarkWahlsten commented 4 years ago

A new thread would probably be good.

Done! Created a new thread here: #1050

PalmerAL commented 4 years ago

Context menu support is done in 3d0961ad2640b7fa4150bfcece9d2b7ece6e1711.