Skip to content

Instantly share code, notes, and snippets.

@satyr
Created January 14, 2009 08:10
Show Gist options
  • Save satyr/46836 to your computer and use it in GitHub Desktop.
Save satyr/46836 to your computer and use it in GitHub Desktop.
Allows accessing Bookmark Toolbar with alt/opt + 1~0.
// ==UserScript==
// @name BookmarKeys
// @namespace http://d.hatena.ne.jp/murky-satyr
// @description Allows accessing Bookmark Toolbar with alt/opt + 1~0.
// @include main
// @compatibility Firefox 3.0+
// @author satyr
// @version 09-12-01
// @note inspired by addons.mozilla.org/en-US/firefox/addon/3647
// ==/UserScript==
function bookmarKey(n){
var bb = document.getElementById('bookmarksBarContent');
var lm = n ? bb.childNodes[n-1] : bb.lastChild;
if(!lm) return;
var mp = lm.firstChild;
if(mp) mp.showPopup();
else {
lm.click();
lm.disabled = true;
setTimeout(function(){ lm.disabled = false }, 333);
}
}
for(let ks = document.getElementById('mainKeyset'), i = 0; i <= 9; ++i){
let k = ks.appendChild(document.createElement('key'));
k.setAttribute('id', 'BookmarKey'+ i);
k.setAttribute('oncommand', 'bookmarKey('+ i +')');
k.setAttribute('modifiers', 'alt');
k.setAttribute('key', i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment