Skip to content

Instantly share code, notes, and snippets.

@manveru
Created February 3, 2009 04:06
Show Gist options
  • Save manveru/57295 to your computer and use it in GitHub Desktop.
Save manveru/57295 to your computer and use it in GitHub Desktop.
Ubiquity command to add bookmarks to http://sm.purepistos.com
CmdUtils.CreateCommand({
name: "selfmark",
homepage: "http://manveru.net",
author: { name: "Michael Fellinger", email: "m.fellinger@gmail.com"},
contributors: ["Michael Fellinger"],
license: "MIT",
description: "Tags the current site using selfmarks",
icon: "http://sm.purepistos.net/favicon.ico",
help: "Save the current url to selfmarks with the tags input by the user. Any selected text on the page will be recorded as the note.",
takes: {note: noun_arb_text},
modifiers: {
tagged: noun_arb_text,
titled: noun_arb_text
},
preview: function(pblock, note, mods){
var params = this.post_params(note, mods);
html = "<p>title: " + params.title + "</p>";
html += "<p>tags: " + params.tags + "</p>";
html += "<p>note: " + params.notes + "</p>";
pblock.innerHTML = html;
},
execute: function(note, mods){
var params = this.post_params(note, mods);
var response = jQuery.post("http://sm.purepistos.net/uri/add", params);
},
post_params: function(note, mods){
var doc = Application.activeWindow.activeTab.document;
var uri = Utils.url(doc.documentURI);
var tags = mods.tagged.text
if(!tags){
tags = jQuery("a[@rel=tag]", doc).map(
function(idx, tag){ return(tag.innerHTML); });
tags = this.unique_tags(tags).join(' ');
}
CmdUtils.log(tags);
var params = {
uri: uri.asciiSpec,
title: mods.titled.text || doc.title,
notes: note.text,
tags: tags
};
return params;
},
unique_tags: function(a){
var r = new Array();
o:for(var i = 0, n = a.length; i < n; i++) {
for(var x = 0, y = r.length; x < y; x++) {
if(r[x]==a[i]) continue o;
}
r[r.length] = a[i];
}
return r;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment