Skip to content

Instantly share code, notes, and snippets.

@satyr
Created August 30, 2009 03:02
Show Gist options
  • Save satyr/177839 to your computer and use it in GitHub Desktop.
Save satyr/177839 to your computer and use it in GitHub Desktop.
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>"));
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment