Skip to content

Instantly share code, notes, and snippets.

@kalisjoshua
Created June 8, 2014 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalisjoshua/500d5efabc7e848804af to your computer and use it in GitHub Desktop.
Save kalisjoshua/500d5efabc7e848804af to your computer and use it in GitHub Desktop.
IETF docs are ugly to look at and I am lazy so I don't like scrolling. This - bookmarklet (optional) - script makes the experience a little better with centered document body and larger text with left/right navigation through pages.
(function (doc) {
doc.body.style.fontSize = '115%';
doc.body.style.margin = '0 auto';
doc.body.style.maxWidth = '37em';
var count,
rPage = /\[\s*?page\s*?(\d+?)\s*?\]/i,
TOP = 'top-of-document';
function turn(delta) {
var current = window.location.hash.slice(1),
next;
if (!current || current === TOP) {
current = 'page-1';
}
current = parseInt(current.split('-').pop(), 10);
next = current + delta;
if (next > 0 && next <= count) {
window.location.hash = 'page-' + next;
}
if (next === 0) {
window.location.hash = TOP;
}
}
[].slice.call(document.querySelectorAll('pre'))
.forEach(function (page) {
var match = page.innerText.match(rPage);
if (match[1]) {
page.id = 'page-' + match[1];
}
});
count = 1 + document.querySelectorAll('pre [id^="page-"]').length;
document.body.id = TOP;
document.addEventListener('keydown', function (event) {
if (!(event.altGraphKey || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)) {
move = {37: -1, 39: 1}[event.keyCode];
if (move) {
event.preventDefault();
turn(move);
}
}
});
}(document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment