manveru (owner)

Revisions

gist: 57295 Download_button fork
public
Description:
Ubiquity command to add bookmarks to http://sm.purepistos.com
Public Clone URL: git://gist.github.com/57295.git
Embed All Files: show embed
selfmarks.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
 }
});