Skip to content

Instantly share code, notes, and snippets.

@958
Created September 1, 2008 23:40
Show Gist options
  • Save 958/8356 to your computer and use it in GitHub Desktop.
Save 958/8356 to your computer and use it in GitHub Desktop.
[Ubiquity]hatena-bookmark-post
CmdUtils.CreateCommand({
name: 'hateb-post',
icon: 'http://b.hatena.ne.jp/favicon.ico',
takes: {'comment': noun_arb_text},
execute: function(directObj){
var comment = directObj.text;
var curURL = context.focusedWindow.document.location.href;
jQuery.ajax({
type: 'GET',
url: 'http://b.hatena.ne.jp/add',
data: 'mode=confirm&is_bm=1&url='+encodeURIComponent(curURL),
error: function(responseData){
displayMessage('An error has been occured.');
},
success: function(res) {
var dom = context.focusedWindow.document.implementation.createDocument(null, 'html', null)
var range = context.focusedWindow.document.createRange();
range.setStartAfter(context.focusedWindow.document.body);
dom.documentElement.appendChild(
dom.importNode(range.createContextualFragment(
res.replace(/^([\n\r]|.)*?<html([\n\r]|.)*?>|<\/html([\n\r]|.)*?>([\n\r]|.)*$/ig, '')
), true)
);
var inputs = jQuery('input', dom.documentElement);
if (inputs.length == 0) {
displayMessage('you are not logging hatena in.');
} else {
if (inputs.length == 1) {
displayMessage('This page has already bookmarked.');
} else {
var opt = {};
inputs.each(function(){ opt[this.getAttribute('name')] = this.getAttribute('value'); });
jQuery.ajax({
type: 'POST',
url: 'http://b.hatena.ne.jp/add',
data: [
'mode=enter',
'&eid=', opt.eid,
'&url=', encodeURIComponent(opt.url),
'&rkm=', encodeURIComponent(opt.rkm),
'&is_bm=', opt.is_bm,
'&title=', encodeURIComponent(opt.title),
'&comment=', encodeURIComponent(comment)
].join(''),
dataType: 'string',
contentType: 'application/x-www-form-urlencoded',
cache: false,
error: function(){
displayMessage('Update has been failed...');
},
success: function(){
displayMessage('done.');
}
});
}
}
}
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment