-
Notifications
You must be signed in to change notification settings - Fork 3
/
arrow-keys.user.js
45 lines (42 loc) · 1.53 KB
/
arrow-keys.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
// ==UserScript==
// @name Browse the reactjs docs with arrow keys
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://reactjs.org/docs/*
// @icon https://www.google.com/s2/favicons?domain=reactjs.org
// @grant none
// ==/UserScript==
(function arrowKeys() {
const $x = function $x(xpathExpression) {
const evaluatedDocument = document.evaluate(xpathExpression, document);
let result = evaluatedDocument.iterateNext();
const results = [];
while (result !== null) {
results.push(result);
result = evaluatedDocument.iterateNext();
}
return results;
};
document.addEventListener(
'keydown',
(event) => event.code === 'ArrowRight'
&& window.location.assign($x("//div[contains(.,'Next article')]/following-sibling::div/a")[0].href),
);
document.addEventListener(
'keydown',
(event) => event.code === 'ArrowLeft'
&& window.location.assign(
$x("//div[contains(.,'Previous article')]/following-sibling::div/a")[0].href,
),
);
document.querySelector('div > header').setAttribute('style', 'display:none;');
document.querySelector('div > footer').setAttribute('style', 'display:none;');
document.querySelector('article ~ div').setAttribute('style', 'display:none;');
document.querySelector('article > div > div ~ div').setAttribute('style', 'display:none;');
$x("//ul/../../div[contains(.,'Previous article') or contains(.,'Next article')]")[0].setAttribute(
'style',
'display:none;',
);
}());