Skip to content

Instantly share code, notes, and snippets.

@mouseboks mouseboks/x
Created Apr 12, 2009

Embed
What would you like to do?
Ubiquity command for accessing Google Bookmarks
if (CmdUtils.parserVersion >= 2) {
//Parser V2 commands
CmdUtils.CreateCommand({
name: 'gbk',
icon: "http://www.google.com/favicon.ico",
author: {name: "James Maidment", email: "james@mouseboks.org.uk"},
license: "GPL",
description: 'Bookmarks the current page using Google Bookmarks',
help: 'Adds the current page you are viewing to your Google Bookmarks account. You can also enter a list of comma-separated labels to add, along with a note.',
arguments: [ {role: 'alias', nountype: noun_arb_text, label: 'labels'},
{role: 'instrument', nountype: noun_arb_text, label: 'note'} ],
preview: function(pblock, args) {
pblock.innerHTML = "Bookmarking: '" + CmdUtils.getDocument().title + "'";
},
execute: function(args) {
//Get the sig parameter we need to be able to post a bookmark
var req = new XMLHttpRequest();
req.open('GET', 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=', false);
req.send(null);
if (req.responseText.search("ServiceLogin") != -1) {
displayMessage(_("Please check you are logged in to <a href="http://www.google.com/bookmarks/">Google Bookmarks</a>"));
return;
}
var sigpos = req.responseText.search("sig=");
var sig = req.responseText.substring(sigpos+4,sigpos+26);
//Make the call the google bookmarks service itself
req = new XMLHttpRequest();
req.open('POST', 'http://www.google.com/bookmarks/mark?sig=' + sig + '&hl=en', false);
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
var document = CmdUtils.getDocument();
req.send('title=' + encodeURIComponent(document.title) + '&bkmk=' + encodeURIComponent(document.location) + '&labels=' + encodeURIComponent(args.alias.text) + '&annotation=' + encodeURIComponent(args.instrument.text));
if (req.status != 200) {
displayMessage(_("Problem creating the bookmark. Error code: ${status} ${statusTest}", {status: req.status, statusText: req.statusText}));
return;
} else {
displayMessage(_("Bookmarked ${title}", {title: document.title}));
}
}
});
CmdUtils.CreateCommand({
name: 'gbk-search',
icon: "http://www.google.com/favicon.ico",
author: {name: "James Maidment", email: "james@mouseboks.org.uk"},
license: "GPL",
description: 'Search your Google Bookmarks',
help: 'Enter a search term to find Google Bookmarks containing that term.',
arguments: [ {role: 'search', nountype: noun_arb_text, label: 'search'} ],
preview: function(pblock, args) {
CmdUtils.previewGet(
pblock,
'http://www.google.com/bookmarks/find',
{'q': args.search.text}, function(data) {
if (data.search("ServiceLogin") != -1) {
pblock.innerHTML = 'Please check you are logged in to <a href="http://www.google.com/bookmarks/">Google Bookmarks</a>';
return;
}
pblock.innerHTML = CmdUtils.renderTemplate('<ul>{for bookmark in bookmarks}<li><a href="${bookmark.title}">${bookmark.innerHTML}</a></li>{forelse}No search results found.{/for}</ul>', {bookmarks: jQuery('a[title]', data).get()});
});
},
execute: function(args) {
Utils.openUrlInBrowser("http://www.google.com/bookmarks/find?q=" + encodeURIComponent(args.search.text));
}
});
}else {
//Parser V1 commands
CmdUtils.CreateCommand({
name: 'gbk',
icon: "http://www.google.com/favicon.ico",
author: {name: "James Maidment", email: "james@mouseboks.org.uk"},
license: "GPL",
description: 'Bookmarks the current page using Google Bookmarks',
help: 'Accepts a list of comma-separated labels to add, along with a note as a modifier',
takes: {'labels': noun_arb_text},
modifiers: {note: noun_arb_text},
preview: function(pblock, input) {
pblock.innerHTML = "Bookmarking: '" + CmdUtils.getDocument().title + "'";
},
execute: function(labels, mods) {
//Get the sig parameter we need to be able to post a bookmark
var req = new XMLHttpRequest();
req.open('GET', 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=', false);
req.send(null);
if (req.responseText.search("ServiceLogin") != -1) {
displayMessage('Please check you are logged in to Google Bookmarks');
return;
}
var sigpos = req.responseText.search("sig=");
var sig = req.responseText.substring(sigpos+4,sigpos+26);
//Make the call the google bookmarks service itself
req = new XMLHttpRequest();
req.open('POST', 'http://www.google.com/bookmarks/mark?sig=' + sig + '&hl=en', false);
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
var document = CmdUtils.getDocument();
req.send('title=' + encodeURIComponent(document.title) + '&bkmk=' + encodeURIComponent(document.location) + '&labels=' + encodeURIComponent(labels.text) + '&annotation=' + encodeURIComponent(mods.note.text));
if (req.status != 200) {
displayMessage('Problem creating the bookmark. Error code: ' + req.status + ' ' + req.statusText);
return;
} else {
displayMessage('Bookmarked ' + document.title);
}
}
});
CmdUtils.CreateCommand({
name: 'gbk-search',
icon: "http://www.google.com/favicon.ico",
author: {name: "James Maidment", email: "james@mouseboks.org.uk"},
license: "GPL",
description: 'Search your Google Bookmarks',
help: '',
takes: {'search': noun_arb_text},
preview: function(pblock, search) {
CmdUtils.previewGet(
pblock,
'http://www.google.com/bookmarks/find',
{'q': search.text}, function(data) {
if (data.search("ServiceLogin") != -1) {
pblock.innerHTML = 'Please check you are logged in to <a href="http://www.google.com/bookmarks/">Google Bookmarks</a>';
return;
}
pblock.innerHTML = CmdUtils.renderTemplate('<ul>{for bookmark in bookmarks}<li><a href="${bookmark.title}">${bookmark.innerHTML}</a></li>{forelse}No search results found.{/for}</ul>', {bookmarks: jQuery('a[title]', data).get()});
});
},
execute: function(search) {
Utils.openUrlInBrowser("http://www.google.com/bookmarks/find?q=" + encodeURIComponent(search.text));
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.