Page 1 of 1

Scrolling article with cursor keys

Posted: 19 Mar 2013, 16:12
by Rinaldus
I don't like to use so strange hotkeys (N and P) to scroll article. I want to scroll with traditional cursor keys. Is possible to switch off tt-rss default hotkeys and scroll articles by system default keys (i.e cursor keys)?

Re: Scrolling article with cursor keys

Posted: 19 Mar 2013, 16:55
by phz
I made a plugin with the following contents:

Code: Select all

<?php
class MyKeys extends Plugin {

   private $link;
   private $host;

   function about() {
      return array(1.0,
         "Personal keyboard configuration",
         "phz");
   }

   function init($host) {
      $this->link = $host->get_link();
      $this->host = $host;

      $host->add_hook($host::HOOK_HOTKEY_MAP, $this);
   }

   function hook_hotkey_map($hotkeys) {
      $hotkeys['(13)|enter']   = 'open_in_new_window';
      $hotkeys['(37)|left']    = 'prev_article_noscroll';
      $hotkeys['(38)|up']      = 'article_scroll_up';
      $hotkeys['(39)|right']   = 'next_article_noscroll';
      $hotkeys['(40)|down']    = 'article_scroll_down';
      $hotkeys['*(38)|s-up']   = 'prev_feed';
      $hotkeys['*(40)|s-down'] = 'next_feed';

      return $hotkeys;
   }
}
?>

It's quite self-explanatory, but more explicitly:
  • Enter opens the current item in a new tab
  • → goes to the next item
  • ← goes to the previous item
  • ↑ scrolls upwards among items
  • ↓ scrolls downwards among items
  • Shift+↑ goes to the previous entry in the feed list
  • Shift+↓ goes to the next entry in the feed list
Note that the Shift-combinations won't work until you run a version with https://github.com/gothfox/Tiny-Tiny-RS ... 022fd5c0f3 applied (next TT-RSS release should have this).

Create a file with the above contents (or modify to your liking), name it `init.php`, put it in `your_tt-rss_folder/plugins/mykeys/`, go to TT-RSS preferences and enable it.

(If someone knows how to create a hotkey to open an article in a background tab they are very welcome to share, but I am aware of that it in general is a browser issue and not a limitation of or in the scope of TT-RSS.)

Re: Scrolling article with cursor keys

Posted: 19 Mar 2013, 17:20
by Rinaldus
Super! Thank you very much! This is what I wanted! Author have to include this plugin into standart set of plugins that ship with distribution.

Re: Scrolling article with cursor keys

Posted: 19 Mar 2013, 18:04
by fox
I too do think that adding 25 plugins named "bob's fav hotkeys" would be an excellent idea for trunk.

Re: Scrolling article with cursor keys

Posted: 19 Mar 2013, 19:10
by cjbnc
Rather than try to have everyone's favorite hotkey settings added to the code as an infinite list of new plugins, it seemed like a good idea to provide one stub plugin that anyone could easily customize to fit their own site.


Plugin code here: viewtopic.php?f=22&t=1382&p=6178
I've added this keymap as another example.

Re: Scrolling article with cursor keys

Posted: 27 Mar 2013, 20:36
by laurion
phz wrote:
(If someone knows how to create a hotkey to open an article in a background tab they are very welcome to share, but I am aware of that it in general is a browser issue and not a limitation of or in the scope of TT-RSS.)


There is a way to do it. I scarfed this from a userscript that did this for GReader, because I too have an intense burning need to open things in the background as I go. I modified the viewfeed.js file in the /js folder, but if anyone can figure out a good way to make a plugin out of it, I'd be very grateful so I don't have to redo this with every update. Anyhow, open up the viewfeed.js file and go to the openArticleInNewWindow function. Change the line there to instead call a new function, which you can add in to the file as well. Here's what I now have:

Code: Select all

function openArticleInNewWindow(id) {
        toggleUnread(id, 0, false);
        //window.open("backend.php?op=article&method=redirect&id=" + id);
        openNewBackgroundTab("backend.php?op=article&method=redirect&id=" + id);
}

function openNewBackgroundTab(url){
    var a = document.createElement("a");
    a.href = url;
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
    a.dispatchEvent(evt);
}




I want it to always open in background tabs, but if you don't want to, you don't have to modify openArticleInNewWindow, you can call the new function directly with a different keyboard shortcut. It works by simulating a ctrl-click on the link.

Re: Scrolling article with cursor keys

Posted: 27 Mar 2013, 23:25
by phz
laurion wrote:
phz wrote:
(If someone knows how to create a hotkey to open an article in a background tab they are very welcome to share, but I am aware of that it in general is a browser issue and not a limitation of or in the scope of TT-RSS.)


There is a way to do it. I scarfed this from a userscript that did this for GReader, because I too have an intense burning need to open things in the background as I go. I modified the viewfeed.js file in the /js folder, but if anyone can figure out a good way to make a plugin out of it, I'd be very grateful so I don't have to redo this with every update. Anyhow, open up the viewfeed.js file and go to the openArticleInNewWindow function. Change the line there to instead call a new function, which you can add in to the file as well. Here's what I now have:

Code: Select all

function openArticleInNewWindow(id) {
        toggleUnread(id, 0, false);
        //window.open("backend.php?op=article&method=redirect&id=" + id);
        openNewBackgroundTab("backend.php?op=article&method=redirect&id=" + id);
}

function openNewBackgroundTab(url){
    var a = document.createElement("a");
    a.href = url;
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
    a.dispatchEvent(evt);
}




I want it to always open in background tabs, but if you don't want to, you don't have to modify openArticleInNewWindow, you can call the new function directly with a different keyboard shortcut. It works by simulating a ctrl-click on the link.

Yeah, I saw that snippet concerning simulating clicks on StackOverflow when I was writing the keyboard shortcuts above. The overwhelming hack factor made and makes me a bit wary :-) . In case it is actually robust in practice I might reevalute, though. Open in background is a lot more natural for my usage of RSS readers at least. Skim through the posts, the ones worth reading goes to background, continue through the list. When done: start reading in depth.

Because of this (and no, Google Reader did not have this functionality either, so no implementation complaints here :-) ) I've become quite skilled at the "Enter Ctrl+Shift+Tab" combo, though, so it's not a deal breaker in any way. I'll see if I'll experiment with the click simulation on a rainy day.

Re: Scrolling article with cursor keys

Posted: 02 Apr 2013, 19:21
by phz
laurion wrote:…if anyone can figure out a good way to make a plugin out of it, I'd be very grateful so I don't have to redo this with every update.

phz wrote:In case it is actually robust in practice I might reevalute, though.

I've been running this for a little while, and it seems alright, but it only works in Chrome/Opera. I threw some pull requests at Fox to be able to create plugins like these in the project, and under his watchful eye they got added.

You can find a thread in the plugin forum or go directly to GitHub. Note that it requires current trunk, or waiting for 1.7.6 which is supposed to be released in two days.