X-Git-Url: https://jasonwoof.com/gitweb/?p=userscripts.git;a=blobdiff_plain;f=numbered_links.user.js;h=30346c1f6dcb4db4f9ce80e62e55a900349a11f8;hp=ec51ef0cd653d29f5a36d866cb1a5f410f6e6729;hb=77342950c5f66d1d4700bf48c88f83eedd602849;hpb=77de05f977c5dfaf03d2c29a31dab7fdf31d2df9 diff --git a/numbered_links.user.js b/numbered_links.user.js index ec51ef0..30346c1 100644 --- a/numbered_links.user.js +++ b/numbered_links.user.js @@ -15,16 +15,55 @@ { -// This is activated (and canceled) by pressing the `/~ key. To change it to a -// differet key, edit the ascii value on line 301 -// -// Also, you can change the character set a few lines down. Don't use the "L" -// key unless you change the on line 235. - - +// This is activated (and canceled) by pressing the ^C +// Press L (first) to switch to one-hand mode + +// I was getting some very funky return values from String.fromCharCode() for +// punctuation keys so I made my own table. You might need to change this for +// your computer/keyboard. You'll need to have every character in "charset" in +// here. + +var key_to_char = { + '84': 't', + '72': 'h', + '83': 's', + '78': 'n', + '68': 'd', + '189': '-', + '82': 'r', + '67': 'c', + '71': 'g', + '77': 'm', + '86': 'v', + '87': 'w', + '66': 'b', + '191': '/', + '186': ';', + '55': '7', + '56': '8', + '57': '9', + '65': 'a', + '69': 'e', + '70': 'f', + '73': 'i', + '74': 'j', + '75': 'k', + '79': 'o', + '80': 'p', + '81': 'q', + '85': 'u', + '88': 'x', + '89': 'y', + '90': 'z', + '50': '2', + '51': '3', + '52': '4', + '222': "'", + '76': 'l' // switch to one-hand mode +} //Just some shortcuts and globals -var charset = 'thsnd-rcgmvwb/;789aefijkopquxyz234'; +var charset = 'thsnd-rcgmvwb/;789aefijkopquxyz234'; // update key_to_char if you add to this var uzblid = 'uzbl_link_hint'; var uzbldivid = uzblid + '_div_container'; var doc = document; @@ -293,12 +332,26 @@ function followLinks(follow) { + // from your event handler you can: return stop_event(e) + function stop_event(e) { + // try { + e.stopPropagation(); + e.preventDefault(); + // } catch (ex) { + // return false; // IE-compat + // } + } var active = 0; var got = ''; document.addEventListener( - 'keypress', + 'keydown', function(e) { - if(e.keyCode == 96) { // change this if you want a different activation key + // [de]activate on ^C + // deactivate on ESC + if( + (e.ctrlKey && e.keyCode == 67) + || (e.keyCode == 27 && active == 1) + ) { if(active) { got = ''; removeAllHints(); @@ -306,11 +359,14 @@ function followLinks(follow) { followLinks(got); } active = 1 - active; - return; + return stop_event(e); } else { - if(active == 1) { - got += String.fromCharCode(e.keyCode); - followLinks(got); + if(active == 1 && !e.ctrlKey && !e.shiftKey && !e.altKey) { + if(key_to_char[e.keyCode]) { + got += key_to_char[e.keyCode]; + followLinks(got); + return stop_event(e); + } } } },