Created
December 26, 2016 00:23
-
-
Save josefandersson/b42abcc6122ddfc3cbced2906f86a1a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name HF Keyboard Shortcuts | |
// @namespace https://github.com/josefandersson/hf_keyboard_shortcuts | |
// @version 1.0.0 | |
// @description Use your keyboard to quickly navigate hackforums using a ton of shortcuts. | |
// @author DrDoof | |
// @match *://hackforums.net/* | |
// @require https://craig.global.ssl.fastly.net/js/mousetrap/mousetrap.min.js | |
// @require https://code.jquery.com/jquery-3.1.0.min.js | |
// @grant GM_addStyle | |
// @grant GM_getResourceText | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @run-at document-end | |
// ==/UserScript== | |
/* | |
shortcut object: | |
{ | |
bind:<key bind>, callback:<callback function, gets passed: UID> | |
} | |
All shortcuts: | |
r - reload current page | |
b - open buddy list - MyBB.popupWindow('https://hackforums.net/misc.php?action=buddypopup', 'buddyList', 350, 350); | |
v - open my reputations - https://hackforums.net/reputation.php?uid={UID} | |
t - open my trust scan - https://hackforums.net/trustscan.php?uid={UID} | |
backspace - go to previous page in history | |
1 - view new posts https://hackforums.net/search.php?action=getnew | |
2 - your threads https://hackforums.net/search.php?action=finduserthreads&uid={UID} | |
3 - your psots https://hackforums.net/search.php?action=finduser&uid={UID} | |
4 - private messages https://hackforums.net/private.php | |
5 - your profile https://hackforums.net/member.php?action=profile | |
6 - user control panel https://hackforums.net/usercp.php | |
alt+1 - home page https://hackforums.net/ | |
alt+2 - upgrades page https://hackforums.net/upgrade.php | |
alt+3 - search page https://hackforums.net/search.php | |
alt+4 - member list page https://hackforums.net/memberlist.php | |
alt+5 - extras page https://hackforums.net/extras.php | |
alt+6 - wiki page http://hackforumswiki.net/ | |
alt+7 - help page https://hackforums.net/misc.php?action=help | |
alt+8 - follow page https://twitter.com/hackforumsnet | |
alt+9 - contact page https://hackforums.net/contact.php | |
alt+0 - open dd database https://hackforums.net/disputedb.php | |
/showthread.php?tid=* | |
e - jump to first post in thread https://hackforums.net/showthread.php?tid={TID}#posts | |
shift+e - jump to first post on page https://hackforums.net/showthread.php?tid={TID}&page={PAGE}#posts | |
w - select previous post | |
s - select next post | |
a - go to previous page | |
d - go to next page | |
q - quote selected post | |
shift+q - add selected post to quote queue | |
shift+f - open post author's profile | |
shift+r - open post author's reputation | |
shift+t - open post author's trust scan | |
shift+g - send a pm to post author | |
//TODO | |
VOTING | |
RATE THREAD | |
BROWSE SUBFORUMS | |
BUDDY LIST POPUP SHOULD NOT HAVE ANY SHORTCUTS EXCEPT FOR ESC TO CLOSE THE WINDOW | |
/search.php?action=results* | |
w - move up a box | |
s - move down a box | |
a - move left a box | |
d - move right a box | |
space - open link in selected box | |
*/ | |
var TID, UID, PAGE; | |
try { TID = /tid=(\d+)/ .exec(window.location.href)[1]; } catch(e) {} | |
try { UID = /uid=(\d+)/ .exec(document.getElementById('panel').innerHTML)[1]; } catch(e) {} | |
try { PAGE = parseInt((/page=(\d+)/.exec(window.location.href) || [undefined,1])[1]); } catch(e) {} | |
var makeSendLinkCallback = function(url) { | |
return e=>{ | |
url = url.replace(/{TID}/g, TID); | |
url = url.replace(/{UID}/g, UID); | |
console.log('Directing to', url); | |
window.location.href = url; | |
}; | |
}; | |
// All the keybindings. | |
var _BINDS = { | |
'.*': { | |
'backspace': { desc:'Go back a page', cb: e=>history.back() }, | |
'r': { desc:'Reload current page', cb: e=>window.location.reload() }, | |
'b': { desc:'Open buddy list', cb: e=>MyBB.popupWindow('https://hackforums.net/misc.php?action=buddypopup', 'buddyList', 350, 350) }, | |
'v': { desc:'Open my reputations', cb: makeSendLinkCallback('https://hackforums.net/reputation.php?uid={UID}') }, | |
't': { desc:'Open my trust scan', cb: makeSendLinkCallback('https://hackforums.net/trustscan.php?uid={UID}') }, | |
'1': { desc:'View new posts', cb: makeSendLinkCallback('https://hackforums.net/search.php?action=getnew') }, | |
'2': { desc:'View your threads', cb: makeSendLinkCallback('https://hackforums.net/search.php?action=finduserthreads&uid={UID}') }, | |
'3': { desc:'View your posts', cb: makeSendLinkCallback('https://hackforums.net/search.php?action=finduser&uid={UID}') }, | |
'4': { desc:'View your PMs', cb: makeSendLinkCallback('https://hackforums.net/private.php') }, | |
'5': { desc:'View your profile', cb: makeSendLinkCallback('https://hackforums.net/member.php?action=profile') }, | |
'6': { desc:'Go to UserCP', cb: makeSendLinkCallback('https://hackforums.net/usercp.php') }, | |
'alt+1': { desc:'Go to home page', cb: makeSendLinkCallback('https://hackforums.net/') }, | |
'alt+2': { desc:'Go to upgrades page', cb: makeSendLinkCallback('https://hackforums.net/upgrade.php') }, | |
'alt+3': { desc:'Go to search page', cb: makeSendLinkCallback('https://hackforums.net/search.php') }, | |
'alt+4': { desc:'Go to members page', cb: makeSendLinkCallback('https://hackforums.net/memberlist.php') }, | |
'alt+5': { desc:'Go to extras page', cb: makeSendLinkCallback('https://hackforums.net/extras.php') }, | |
'alt+6': { desc:'Go to wiki page', cb: makeSendLinkCallback('http://hackforumswiki.net/') }, | |
'alt+7': { desc:'Go to help page', cb: makeSendLinkCallback('https://hackforums.net/misc.php?action=help') }, | |
'alt+8': { desc:'Go to follow page', cb: makeSendLinkCallback('https://twitter.com/hackforumsnet') }, | |
'alt+9': { desc:'Go to contact page', cb: makeSendLinkCallback('https://hackforums.net/contact.php') }, | |
'alt+0': { desc:'Go to DD database', cb: makeSendLinkCallback('https://hackforums.net/disputedb.php') }, | |
}, | |
'/showthread\\.php\\?tid=.*': { | |
'e': { desc:'Jump to first post in thread', cb: makeSendLinkCallback('https://hackforums.net/showthread.php?tid={TID}#posts') }, | |
'shift+e': { desc:'Jump to first post on page', cb: makeSendLinkCallback('https://hackforums.net/showthread.php?tid={TID}&page={PAGE}#posts') }, | |
'w': { desc:'Jump to previous post', cb: e=>{} }, | |
's': { desc:'Jump to next post', cb: e=>{} }, | |
'a': { desc:'Jump to previous page', cb: e=>{ makeSendLinkCallback(`https://hackforums.net/showthread.php?tid={TID}&page=${ PAGE-1 }#posts`)(); } }, | |
'd': { desc:'Jump to next page', cb: e=>{ makeSendLinkCallback(`https://hackforums.net/showthread.php?tid={TID}&page=${ PAGE+1 }#posts`)(); } }, | |
'q': { desc:'Quote selected post', cb: e=>{} }, | |
} | |
}; | |
(function() { | |
var page, shortcut; | |
for (var page_match in _BINDS) { | |
if (new window.RegExp(page_match).test(window.location.href)) { | |
page = _BINDS[page_match]; | |
for (var bind in _BINDS[page_match]) { | |
shortcut = page[bind]; | |
Mousetrap.bind(bind, shortcut.cb); | |
//console.log('Binded shortcut:', bind, '-', shortcut.desc); | |
} | |
} | |
} | |
})(); | |
/* | |
//*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment