2

I'm using Pentadactyl, a Firefox plugin which emulates vim-style keybindings and browsing. I've recently been interested in using Pocket with 'Automatically make all saved pages available offline' checked as a simple way to save and manage articles for offline viewing.

Pocket saves pages with a button in the URL bar. There's also a button for the toolbar, but that doesn't seem to do anything for me and only shows a white box. There's also an option for it in the right-click menu, and a bookmark to add it to your pocket account. I can't seem to find a way to call any of these options using Pentadactyl commands.

The only :emenu pocket command I can find is for showing and hiding the sidebar. There's a way to bind commands to the bookmark, but I frequently have extremely slow internet and this requires waiting for Pocket to add the page to my account, then sync with my local files, and then download the file for offline viewing.

Is there any way to define a Pentadactyl command for accessing addon actions that I'm missing? I also can't seem to find a way to access context menu entries, or I could use the command there. Thanks for any help.

kstew
  • 68

4 Answers4

2

I got it working with tags. Add this to your pentadactylrc:

command! pocket -nargs=* :open javascript:(function(){window.open('https://getpocket.com/edit?url='+escape(window.location.href)+'&tags=<args>', '_self');})()

than trigger via:

:pocket optionalFirstTag,optionalSecondTag

Tags will not show up in the loaded page, but will be saved to the your reading list. To have it open in a new tab change the code from '_self' to '_blank'.

If anyone knows how to throw in a link from hint mode without visiting it that would be great.

1
  • You can install the Pocket bookmarklet and assign a keyword to it, which will let you activate it using o followed by the keyword. Eg. opocEnter

  • Alternatively, you can convert the bookmarklet code to a command and save it in your .pentadactylrc:

     command! pocket :open javascript:(function(){var%20e=function(t,n,r,i,s){var%20o=[3526112,5522661,1460314,3450302,5361262,5114635,2897350,3675444,1446118,2801611];var%20i=i||0,u=0,n=n||[],r=r||0,s=s||0;var%20a={'a':97,'b':98,'c':99,'d':100,'e':101,'f':102,'g':103,'h':104,'i':105,'j':106,'k':107,'l':108,'m':109,'n':110,'o':111,'p':112,'q':113,'r':114,'s':115,'t':116,'u':117,'v':118,'w':119,'x':120,'y':121,'z':122,'A':65,'B':66,'C':67,'D':68,'E':69,'F':70,'G':71,'H':72,'I':73,'J':74,'K':75,'L':76,'M':77,'N':78,'O':79,'P':80,'Q':81,'R':82,'S':83,'T':84,'U':85,'V':86,'W':87,'X':88,'Y':89,'Z':90,'0':48,'1':49,'2':50,'3':51,'4':52,'5':53,'6':54,'7':55,'8':56,'9':57,'\/':47,':':58,'?':63,'=':61,'-':45,'_':95,'&':38,'$':36,'!':33,'.':46};if(!s||s==0){t=o[0]+t}for(var%20f=0;f<t.length;f++){var%20l=function(e,t){return%20a[e[t]]?a[e[t]]:e.charCodeAt(t)}(t,f);if(!l*1)l=3;var%20c=l*(o[i]+l*o[u%o.length]);n[r]=(n[r]?n[r]+c:c)+s+u;var%20p=c%(50*1);if(n[p]){var%20d=n[r];n[r]=n[p];n[p]=d}u+=c;r=r==50?0:r+1;i=i==o.length-1?0:i+1}if(s==166){var%20v='';for(var%20f=0;f<n.length;f++){v+=String.fromCharCode(n[f]%(25*1)+97)}o=function(){};return%20v+'ce5c747776'}else{return%20e(u+'',n,r,i,s+1)}};var%20t=document,n=t.location.href,r=t.title;var%20i=e(n);var%20s=t.createElement('script');s.type='text/javascript';s.src='https://getpocket.com/b/r4.js?h='+i+'&u='+encodeURIComponent(n)+'&t='+encodeURIComponent(r);e=i=function(){};var%20o=t.getElementsByTagName('head')[0]||t.documentElement;o.appendChild(s)})()
    

    Then you can save a page using :pocketEnter

  • If you want to save all tabs to pocket, you can include this command in your .pentadactylrc:

     command! pocketall -js RIL.saveTabs()
    

    note: unlike the previous command, this one doesn't cause a banner to appear


Accessing extension functionality in general.

To answer your more general question, you can often access extensions' functionality via javascript, but it generally involves some exploration and trial and error. There are two ways to run javascript from pentadactyl:

  1. :js ...
  2. :open javascript: ... (or equivalently, ojavascript: ...)

    This is just like running a bookmarklet: it's using the open document command with the javascript: "pseudo-protocol".

The two methods run the javascript in different contexts. In the latter, the global object is the standard window object, which provides client code access to the browser. In the former, the global object is a ChromeWindow object which gives you access to more internals of the browser, including Firefox UI elements and extension objects that aren't available in the window object.

You can explore the ChromeWindow object using pentadactyl's command line completion. Type :jsSpaceTAB and you'll get a scrollable list of completions. Now continue: RIL.TAB and you'll get a list of members of the RIL object (belonging to the Pocket extension).

Another tool is the Firefox Browser Console, which runs in the same context. You can access it with Ctrl-Shift-j. This provides an interactive command line and an object inspector.

Finally, you might want to poke into the extension's files in your profile directory (in GNU/Linux, it's usually $HOME/.mozilla/firefox/PROFILE_NAME/extensions/). This can give you hints on what to look for. For instance, even without actually opening any source files, the names told me to look for objects starting "RIL" when I was looking for the pocket extension's functionality.

pyrocrasty
  • 1,460
1

There are several additional options:

  1. You can switch to Instapaper (export links from Pocket, and then use Instapaper "Import from pocket" setting) and use my native instapaper plugin for pentadactyl.
  2. If you have some time and willing you can adopt vimperator plugin for readitlater (pocket) for pentadactyl. It isn't so hard as you can expect.
petRUShka
  • 255
  • 2
  • 10
0

You can do it easily with a bookmarklet.

  1. Go to this website: https://getpocket.com/add?sb=1
  2. Right click the red bookmarklet button, then click "Copy Link Location"
  3. Put this line in your ~/.pentadactylrc file and replace #BOOKMARKLET LINK# with the URL you just copied:

    command! pocket -description "Save to Pocket" open #BOOKMARKLET LINK#

Now you can simply use the :pocket ex command when you're on a page you want to save.

Hope this helps.

Source: http://www.martinjosefsson.com/2012/10/30/pocket-and-pentadactyl.html