Created
February 7, 2009 09:24
-
-
Save satyr/59842 to your computer and use it in GitHub Desktop.
Executes a bookmarklet from your favorites.
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
Components.utils.import('resource://gre/modules/utils.js'); | |
const noun_type_b00kmarklet = { | |
_name: 'b00kmarklet', | |
suggest: function(txt, htm, cb, sx){ | |
if(!txt) return []; | |
try { var matcher = RegExp(txt, 'i') } | |
catch(_){ matcher = {test: function(x) ~x.indexOf(txt)} } | |
return [{data: b.uri, summary: b.title} | |
for each(b in this.list) if(matcher.test(b.title))]; | |
}, | |
init: function(){ | |
var ls = [], {bookmarks, history} = PlacesUtils, | |
query = history.getNewQuery(), options = history.getNewQueryOptions(); | |
query.onlyBookmarked = true; | |
query.searchTerms = 'javascript:'; | |
({QUERY_TYPE_BOOKMARKS: options.queryType, | |
SORT_BY_TITLE_DESCENDING: options.sortingMode}) = options; | |
var {root} = history.executeQuery(query, options); | |
root.containerOpen = true; | |
for(var i = root.childCount; i--;){ | |
var node = root.getChild(i); | |
if(!bookmarks.getKeywordForBookmark(node.itemId) && | |
/^javascript:/.test(node.uri)) ls.push(node); | |
} | |
root.containerOpen = false; | |
this.list = ls; | |
return this; | |
}, | |
}.init(); | |
CmdUtils.CreateCommand({ | |
name: 'bookmarklet', | |
synonyms: ['bml'], | |
icon: 'chrome://ubiquity/skin/icons/application_view_list.png', | |
takes: {title: noun_type_b00kmarklet}, | |
description: 'Executes a bookmarklet from your favorites.', | |
help: 'Enter nothing to refresh the list.', | |
execute: function({data}){ | |
if(data) CmdUtils.getWindow().location = data; | |
else noun_type_b00kmarklet.init(); | |
}, | |
preview: function(pbl, {data}){ | |
pbl.innerHTML = (data | |
? (<div class={this.name} | |
><pre style="white-space:pre-wrap;margin:2px" >{ | |
decodeURI(data)}</pre></div>) | |
: this.description); | |
}, | |
author: 'satyr'.link('http://d.hatena.ne.jp/murky-satyr'), license: 'MIT', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment