NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Hugelol keyboard navigator // @namespace io.bitcode.hugelol // @description Enables keyboard navigation on all sub-sites of Hugelol. Use arrow keys to navigate back and forth. // @include /^(https?:\/\/)?(www\.)?huge[^lol].*(\.com)[\/]?.*$/ // @version 1.6 // @grant none // @require http://code.jquery.com/jquery-1.11.3.min.js // @copyright 2015, Limnic // ==/UserScript== var nextButton; var previousButton; var jsonOptions; var loadFromUrl = false; var formatUrl = 'format.json'; if (loadFromUrl) { jsonOptions = Object.create(null); } else { jsonOptions = { 'next_arrow_prefix': '<span style="background: white; border-radius: 3px; padding: 3px; padding-bottom: 0px; color: #32A5F1; margin-left: 3px; margin-top: 3px;"><font size="+0"><b>', 'previous_arrow_prefix': '<span style="background: white; border-radius: 3px; padding: 3px; padding-bottom: 0px; color: #32A5F1; margin-right: 3px; margin-top: 3px;"><font size="+0"><b>', 'next_arrow_suffix': '</b></font></span>', 'previous_arrow_suffix': '</b></font></span>', 'next_key': 39, 'previous_key': 37, 'on_button_handle': function (button) { button.css({'background': '#0F8BDB', 'box-shadow': '0 1px 0 #0F8BDB'}); } }; } $('body').keypress(function (event) { if (event.keyCode === jsonOptions.next_key) { if (typeof nextButton !== 'undefined' && typeof nextButton.attr('href') !== 'undefined') { jsonOptions.on_button_handle(nextButton); window.location.href = nextButton.attr('href'); } } else if (event.keyCode === jsonOptions.previous_key) { if (typeof previousButton !== 'undefined' && typeof previousButton.attr('href') !== 'undefined') { jsonOptions.on_button_handle(previousButton); window.location.href = previousButton.attr('href'); } } }); $('body').ready(function () { nextButton = $('a:contains(\'Next Post\')'); previousButton = $('a:contains(\'Previous Post\')'); if (loadFromUrl) { $.getJSON(formatUrl, function (data) { $.each(data, function (key, val) { jsonOptions[key] = val; }); }); } console.log('Hugelol navigator is active! 2'); nextButton.html('Next Post ' + formatArrow('►')); previousButton.html(formatArrow('◄') + ' Previous Post'); $('#subheader').ready(function () { console.log('navigation enabled'); var subHeader = $('#subheader'); console.log(subHeader.length); subHeader.append('<span style=\'text-align: right; color: white; display: block; float: right;\'>Navigate by using ' + formatArrow('◄') + ' and ' + formatArrow('►') + '</span>'); }); }); function formatArrow(arrow) { var sel = 'next'; if (arrow === '►') { sel = 'next'; } else { sel = 'previous'; } return jsonOptions[sel + '_arrow_prefix'] + arrow + jsonOptions[sel + '_arrow_suffix']; }