Created
February 3, 2009 04:06
-
-
Save manveru/57295 to your computer and use it in GitHub Desktop.
Ubiquity command to add bookmarks to http://sm.purepistos.com
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
CmdUtils.CreateCommand({ | |
name: "selfmark", | |
homepage: "http://manveru.net", | |
author: { name: "Michael Fellinger", email: "[email protected]"}, | |
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