satyr (owner)

Revisions

gist: 177839 Download_button fork
public
Description:
https://wiki.mozilla.org/Labs/Ubiquity/Ubiquity_0.5_Author_Tutorial#Using_Bin
Public Clone URL: git://gist.github.com/177839.git
Embed All Files: show embed
bin-sample.ubiq.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
var gId = 42; // used for avoiding needless preview updates when typing
CmdUtils.CreateCommand({
  name: "memo",
  description: "Lets you jot a memo for the page.",
  author: "satyr",
  argument: noun_arb_text,
  execute: function memo_execute({object: {html}}) {
    var {href} = CmdUtils.getDocument().location;
    var list = Bin[href]() || [];
    list.push(html);
    Bin[href](list);
    gId = +new Date;
  },
  preview: function memo_preview(pb) {
    var {href} = CmdUtils.getDocument().location;
    var list = Bin[href]();
    if (!list) {
      pb.innerHTML =
        <>No memos taken for: <small><code>{href}</code></small></>;
      return;
    }
    if (pb.ownerDocument.getElementById(gId)) return;
    var ol = CmdUtils.previewList(pb, list, function deleteMemo(i, ev) {
      $(ev.target).closest("li").slideUp();
      list.splice(i, 1);
      Bin[href](list.length ? list : null);
      gId = +new Date;
    });
    ol.id = gId;
  },
});
 
CmdUtils.CreateCommand({
  name: "list memos",
  description: "Opens all memos you've taken in a new tab.",
  author: "satyr",
  execute: function list_memos_execute() {
    var htm = +Bin + " page(s)<dl>", {escapeHtml} = Utils;
    for (var [url, memos] in Bin) {
      htm += "<dt>" + escapeHtml(url) + "</dt><dd><ol>";
      for each (var memo in memos) htm += "<li>" + memo + "</li>";
      htm += "</ol></dd>";
    }
    Utils.openUrlInBrowser("data:text/html," + encodeURI(htm + "</dl>"));
  },
});