-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathljnav.user.js
53 lines (47 loc) · 1.88 KB
/
ljnav.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ==UserScript==
// @name LJ posts shortcut navigation
// @name:ru Быстрые клавиши для навигация по постам в ЖЖ
// @description Add Ctrl-→ and Ctrl-← shortcut navigation to go to Next/Prev journal entries.
// @description:ru Нажатие Ctrl-→ и Ctrl-← кидает на следующий/предыдущий пост
// @namespace https://github.com/totalamd
// @match *://*.livejournal.com/*
// @version 1.1.1
// @grant none
// @downloadURL https://github.com/totalamd/GM-scripts/raw/master/ljnav.user.js
// @updateURL https://github.com/totalamd/GM-scripts/raw/master/ljnav.user.js
// @noframes
// ==/UserScript==
// changelog:
// [x] disable shortcuts in TEXTAREA and INPUT
// [x] make all regexps variables
"use strict";
const l = function(){}, i = function(){};
(function () {
// const l = console.log.bind(console), i = console.info.bind(console);
let journal, itemid, prevEntry, nextEntry;
const journalRE = /(^[^.]*)\.livejournal.com$/;
const itemidRE = /\/(\d+)\.html$/;
if ((journal = document.location.hostname.match(journalRE)) && (itemid = document.location.pathname.match(itemidRE))) {
prevEntry = 'http://www.livejournal.com/go.bml?journal=' + journal[1] + '&itemid=' + itemid[1] + '&dir=prev';
nextEntry = 'http://www.livejournal.com/go.bml?journal=' + journal[1] + '&itemid=' + itemid[1] + '&dir=next';
l('journal', 'itemid');
} else {
return;
}
document.addEventListener('keydown', function (e) {
if (e.target.tagName === 'TEXTAREA' || e.target.tagName === 'INPUT') {
l('TEXTAREA or INPUT');
return;
};
// left arrow pressed
if (e.ctrlKey && e.keyCode == 37) {
document.location = prevEntry;
e.preventDefault();
}
// right arrow pressed
if (e.ctrlKey && e.keyCode == 39) {
document.location = nextEntry;
e.preventDefault();
}
})
}())