Skip to content

Instantly share code, notes, and snippets.

@anekos
Created May 27, 2011 16:45
Show Gist options
  • Save anekos/995653 to your computer and use it in GitHub Desktop.
Save anekos/995653 to your computer and use it in GitHub Desktop.
Google Bookmarks Completer for Vimperator
let cacheLimit = 30 * 60 * 1000;
let xmlCache;
let getting;
function setCompletions (context, doc) {
let cs = [];
for ([, e] in Iterator(doc.querySelectorAll('bookmark'))) {
let title = e.querySelector('title');
let url = e.querySelector('url');
if (url)
cs.push([url.textContent, title && title.textContent]);
}
context.completions = cs;
}
completion.addUrlCompleter(
'G',
'Google Bookmark',
function (context, args) {
context.incomplete = false;
context.filters = [CompletionContext.Filter.textDescription];
context.title = ["Google Bookmark", "Description"];
if (xmlCache) {
setCompletions(context, xmlCache);
} else {
if (getting)
return;
getting = true;
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
getting = false;
if (xhr.status == 200) {
xmlCache = xhr.responseXML;
setCompletions(context, xhr.responseXML);
context.incomplete = false;
}
setTimeout(function () (xmlCache = void 0), cacheLimit);
}
};
xhr.open("GET", 'https://www.google.com/bookmarks/find?output=xml&q=', true);
xhr.send(null);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment