Last active
August 29, 2015 14:03
-
-
Save azu/491fa1c5050fc378c746 to your computer and use it in GitHub Desktop.
LDRをj、kで前後の記事、nで新しいタブで開くGreasemonkey - http://la.ma.la/blog/diary_200604261407.htm
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
// ==UserScript== | |
// @name ldr_keyhack_jkc+n | |
// @namespace http://ma.la/ | |
// @include http://reader.livedoor.com/reader/* | |
// @version 1.0 | |
// @grant GM_openInTab | |
// ==/UserScript== | |
function main() { | |
function openNewBackgroundTab(url) { | |
GM_openInTab(url, true); | |
} | |
function exportGMFunc(fn, name) { | |
var fnName = name || fn.name; | |
exportFunction(fn, unsafeWindow, {defineAs: fnName }); | |
return unsafeWindow[fnName]; | |
} | |
var w = unsafeWindow; | |
w.Keybind.add("j", w.Control.go_next); | |
w.Keybind.add("k", w.Control.go_prev); | |
// 背面タブで開いて次の記事に移動 | |
var openAndGoNext = function () { | |
var item = w.get_active_item(true); | |
if (!item) { | |
return; | |
} | |
// background open | |
openNewBackgroundTab(htmlEntityDecode(item.link)); | |
w.Control.go_next(); | |
}; | |
w.Keybind.add("n", exportGMFunc(openAndGoNext)); | |
// HTMLエンティティしたものを戻す | |
function htmlEntityDecode(str) { | |
return str.replace(/&(lt|gt|quot|amp);/g, function (_, _1) { | |
return {lt: '<', gt: '>', quot: '"', amp: '&'}[_1]; | |
}); | |
} | |
} | |
window.addEventListener("load", main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment