Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Bind JS scripts/bookmarklets? (for pocket integration) #45

Open
cougarten opened this issue Sep 12, 2017 · 6 comments · May be fixed by #79
Open

Bind JS scripts/bookmarklets? (for pocket integration) #45

cougarten opened this issue Sep 12, 2017 · 6 comments · May be fixed by #79

Comments

@cougarten
Copy link

cougarten commented Sep 12, 2017

Hi,
looking at the structure of this wonderful plugin it seems trivial to add some custom js, but can you hint me at where to add it (without loosing it with updates etc) and how to bind it?

Simply triggering a bookmarklet-style js and bind it to a key would be great!

I want it to add pages to pocket via (contrary to their old bookmarklet, this undocumented url still works):
javascript:(function(){window.open('https://getpocket.com/edit?url='+escape(window.location.href)', '_self');})

Additional things that would be nice:

  • pass a URL from hint mode instead of using window.location.href (I'd use a new tab with target _blank than)
  • load the page in a background tab (or better yet, just send a get request, but never actually show it)
  • pass some arguments as tags, but I'm not sure where that could be added in saka-key. The js with <args> would be: javascript:(function(){window.open('https://getpocket.com/edit?url='+escape(window.location.href)+'&tags=<args>', '_self');})

Thank you so much for providing an alternative to the other keyboard-wizardry add-ons that are now becoming legacy. I thought I'd leave FF behind for good (and install your extention on chrome, hehe) and I'm so happy I can stay!

@eejdoowad
Copy link
Member

eejdoowad commented Sep 13, 2017

Custom commands are tricky to implement because they involve so many different components of Saka Key including:

  • The Options Page
  • The storage, import, and export logic
  • Command mode
  • Dynamically evaluating Javascript

But your post inspired me, so I sketched out a proposal for custom commands in #28. I think it should meet your needs. This will be fun to implement, so it should be out by this weekend.

  • I really like your proposal to use hints mode to activate commands. I've added a todo for this in TODOs: A list of tasks sorted by difficulty to make Saka Key better #18.

  • If you want to send a GET request, you can use the Fetch API from any Javascript function. I'll add an API to forward fetch requests to the background page because websites may have Content Security Policies that block requests to external domains.

  • Your suggestion to pass arguments gave me an idea. After activating a command or selecting a hint, you can switch to Args mode, which is just a text box that submits whatever you enter as an argument to your command.

@kevincox
Copy link

Hi, what is holding this back? The next release of ff is looming so I can probably find some time to implement this feature. Is there any blocker, or just waiting on someone to put in the time?

@eejdoowad
Copy link
Member

eejdoowad commented Oct 16, 2017

The main blocker is my lack of time as of late. The other blocker is that there are subtle issues you have to take care of when providing implementing custom commands.

  1. No JavaScript evaluation in the background page
  2. When to evaluate custom command JavaScript
  3. Where to evaluate custom command JavaScript
  4. How to make custom commands work across multiple frames of a page
  5. How to make hints mode accessible to custom commands
  6. How to store and propagate custom commands
  7. How to let users add custom commands using the options page

I can share a design that addresses many of these issues if you're interested in helping with the implementation. I've also made some baby steps toward the implementation myself.

@kevincox
Copy link

I'd appreciate what you have so far. I'm starting to read the code but I'm not too familar with webextensions or saka-key so it will take me a while to get hacking.

@eejdoowad
Copy link
Member

Have a look at https://key.saka.io/dev_docs/

@kevincox
Copy link

Yup, I've been reading through those :)

@kevincox kevincox linked a pull request Oct 16, 2017 that will close this issue
9 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants