VBulletin keyboard navigation (a bit half-****, but works)

 

I really don’t like web forums all that much, I think they all suck in one way or another and I really yearn for the good old USENET days when everybody was free to use their reader of choice… well, those were the days.

 

With “vBulletin” being a vey prolific and widespread software for many forums / fora / forae I visit regularly, I wanted to bring some comfort back to browsing them by adding some simple keyboard navigation using some javascript I freely “borrowed” from the web sites out there.

 

Here’s the result:

 

“n” – Search for new posts

“g” – go to the first post in the list of new posts

“j/k” – navigate forward / backward in the pages of a thread and / or search results

Cut & Paste the script below and save it to a location of your choice, then you can use the  “tampermonkey” extension for Chrome and other browsers to enable these features (chrome stopped accepting non-store based extensions a year ago for whatever reasons they saw fit, tampermonkey helps to get chrome back under the user’s control)

Add the URLs of your favourite forums to the script and import it into tampermonkey (some niftier form of configuration may be on the cards, but I’m lazy so feel free to add it yourself if you want to).

I hope you find this script useful, enjoy keyboard navigation in vB! 😉

VBB “What’s new” user Script

// ==UserScript==
// @name VBB Show new posts
// @namespace http://www.schuerkamp.de/greasemonkeyhacks/
// @description Adds a "whats new" search link and some shortcuts to vbb forum pages
// @description Download URL: http://dl.dropbox.com/u/1983539/isi_whatsnew.user.js
// ##### ADD THE URL of your vB forums below ##################
// @include http*://*isiforums.net/*
// @include http*://*www.bmsforum.org/*
// 
// ==/UserScript==

var EuropeanDateFormat=1; 
var newlink = document.createElement('a');
var todays_posts = document.createElement('a');
newlink.href = 'search.php?do=getnew&contenttype=vBForum_Post';
todays_posts.href = 'search.php?do=getdaily&contenttype=vBForum_Post';
tn = document.createTextNode(' Show new posts ');
newlink.appendChild(tn);
tn2 = document.createTextNode(' Show todays posts');
todays_posts.appendChild(tn2);

var footer = document.getElementById('footer_links');

if (footer) {
 footer.appendChild(newlink);
 footer.appendChild(todays_posts); 
}

// quick hack to set a default email address
from = document.getElementById('it_from_3');
if (from) {
 from.value="beta-applications@imagespaceinc.com"; 
}

if (EuropeanDateFormat == 1) {
 var dates = document.getElementsByClassName('date');
 for (var i = 0 ; i < dates.length ; i++) {
 var post_date = dates[i].innerText;
 // check if there's a year string in the -2012 notation (will stop working in 2100 ;-) 
 if (post_date.indexOf("-20") != -1 ) {
 year = post_date.substring(6, 10);
 month = post_date.substring(0, 2);
 day = post_date.substring(3, 5);
 var new_date = ""; 
 dates[i].innerText = year + "/" + month + "/" + day; 
 }
 } 
}

// stolen shamelessly from userscript.org's facebook key navigation
// Thanks to Droll Troll

function OnKeyUp(e)
{
 var anchors = document.getElementsByTagName('a');
 for (var i = 0 ; i < anchors.length ; i++) {
 var href = anchors[i].getAttribute('href'); 
 if (href) {
 if(href.match(/goto=newpost/)) {
 break ; 
 }
 }
 } 

 // do a search if we cannot find the "next page" link
 next_page_or_new ="search.php?do=getnew&contenttype=vBForum_Post"
 for (var i = 0 ; i < anchors.length ; i++) {
 var next_page_href = anchors[i].getAttribute('href'); 
 var title01 = anchors[i].getAttribute('title'); 
 if (title01) {
 if(title01.match(/Next Page/)) {
 next_page_or_new = next_page_href
 break ; 
 }
 }
 } 

 prev_page_or_new ="search.php?do=getnew&contenttype=vBForum_Post"
 for (var i = 0 ; i < anchors.length ; i++) {
 var prev_page_href = anchors[i].getAttribute('href'); 
 var title01 = anchors[i].getAttribute('title'); 
 if (title01) {
 if(title01.match(/Prev Page/)) {
 prev_page_or_new = prev_page_href
 break ; 
 }
 }
 } 

 key_map = {
 "N" : "search.php?do=getnew&contenttype=vBForum_Post",
 "G" : href,
 "K" : next_page_or_new, 
 "J" : prev_page_or_new, 
 "T" : 'search.php?do=getdaily&contenttype=vBForum_Post'
 }

 if (String.fromCharCode(e.keyCode) in key_map && 
 (typeof e.target.type == "undefined" || (e.target.type != "text" && e.target.type != "textarea")) && 
 !e.altKey && !e.ctrlKey && e.keyCode <= 90)
 {
 window.location.replace(key_map[String.fromCharCode(e.keyCode)])
 }
}

window.addEventListener("keyup",function(event) { OnKeyUp(event); },false)



Leave a Reply

Your email address will not be published. Required fields are marked *