Created
April 5, 2013 23:25
-
-
Save phmongeau/5323462 to your computer and use it in GitHub Desktop.
a plugin for ttrss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAdjacentArticleId() { | |
var next_id, prev_id | |
var rows = getVisibleArticleIds(); | |
var c_id = ""+getActiveArticleId(); | |
if (!c_id) { | |
next_id = rows[0]; | |
prev_id = rows[rows.length-1] | |
} else { | |
c_index = rows.indexOf(c_id); | |
if(c_index < rows.length - 1) | |
next_id = rows[c_index + 1]; | |
else next_id = rows[0]; | |
if(c_index > 0) | |
prev_id = rows[c_index - 1] | |
else prev_id = rows[rows.length -1]; | |
} | |
return [prev_id, next_id]; | |
} | |
function focusPost(direction) { | |
toggleSelected(getActiveArticleId()); | |
var adjacent = getAdjacentArticleId(); | |
var id = direction == "next" ? adjacent[1] : adjacent[0]; | |
setActiveArticleId(id); | |
toggleSelected(id); | |
} | |
$(document).observe("dom:loaded", function () { | |
hotkey_actions["focus_next_article"] = function() { | |
focusPost("next"); | |
}; | |
hotkey_actions["focus_prev_article"] = function() { | |
focusPost("prev"); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PhMongeau_Keys extends Plugin { | |
private $link; | |
private $host; | |
function about() { | |
return array(1.0, | |
"Swap j and k hotkeys (for vi brethren)", | |
"phmongeau"); | |
} | |
function init($host) { | |
$this->link = $host->get_link(); | |
$this->host = $host; | |
$host->add_hook($host::HOOK_HOTKEY_MAP, $this); | |
} | |
function get_js() { | |
return file_get_contents(dirname(__FILE__) . "/init.js"); | |
} | |
function hook_hotkey_map($hotkeys) { | |
$hotkeys["n"] = "focus_next_article"; | |
$hotkeys["p"] = "focus_prev_article"; | |
$hotkeys["j"] = "next_article_noscroll"; | |
$hotkeys["k"] = "prev_article_noscroll"; | |
$hotkeys["o"] = "collapse_article"; | |
$hotkeys["*n"] = "next_feed"; | |
$hotkeys["*p"] = "prev_feed"; | |
$hotkeys["v"] = "open_in_new_window"; | |
$hotkeys["r"] = "feed_refresh"; | |
return $hotkeys; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment