2008/01/31

Recent entries from same category

  1. Google Reader Full FeedをFirefox3.6対応した。
  2. Twitterの発言から、その前後の会話を簡単に知る方法
  3. グー!ググググー!ルッキングーでございます。(エドはるみグリモン書いた)
  4. Qaaに回答を投げるMinibufferコマンド書いた
  5. Minibufferから「We Heart It」出来るグリモン「weheartit.user.js」書いた

MinibufferBookmarkCommand - 3.14

適当ですが...
はてなブックマークと違いdel.icio.usの場合は、クローラでタイトルを補完してくれませんので、XHRで自前で取得しています。その際、responseTextが文字化けを起こしている可能性がありますので要注意。
--- minibufferbookmarkcomman.user.js.orig   Sat Nov 24 14:53:01 2007
+++ minibufferbookmarkcomman.user.js    Sat Nov 24 14:51:57 2007
@@ -140,6 +140,90 @@
        postToHatenaB(nodes, urls);
    }
    
+   // delicious bookmark
+   var delicious = function(nodes, urls, tags, comment){
+       if(!urls.length) return;
+       var total = urls.length;
+       var time = new Date().getTime();
+       var getParam = function(node, url, fn, afterPost){
+           if(!url) return;
+           var callback = function(res){
+               var html = res.responseText.createHTML();
+               var form = window.Minibuffer.$X('//form[@id="delForm"]', html)[0];
+               var inputs = window.Minibuffer.$X('//form[@id="delForm"]//input', html);
+               var res = {};
+               inputs.forEach(function(node){
+                   res[node.getAttribute('name')] = node.getAttribute('value');
+               });
+               if(keys(res).length == 1){
+                   // already bookmarked
+                   var text = url;
+                   if(window.LDRize){
+                       var siteinfo = window.LDRize.getSiteinfo();
+                       if(siteinfo && siteinfo.view){
+                           var view = window.Minibuffer.$X(siteinfo.view, node)[0];
+                           if(view) text = view.textContent;
+                       }
+                   }
+                   window.Minibuffer.message('<small>'+text+'</small><br/> has already bookmarked.', 2000);
+                   afterPost();
+               }else{
+                   res.action = 'http://del.icio.us/' + form.action.replace(/^https?:\/\/[^\/]+\//, '');
+                   // not yet bookmarked
+                   fn(res, afterPost);
+               }
+           }
+           GM_xmlhttpRequest({
+             method: 'GET',
+             url: "http://del.icio.us/post?v=4&url="+encodeURIComponent(url),
+             onload: callback,
+             onerror: function(res){log('onerror',res.responseText, '\n',res.responseHeaders)},
+           });
+       }
+       var post = function(opt, afterPost){
+           if (!opt.description) {
+               var x = new XMLHttpRequest();
+               x.open('GET', opt.url, false);
+               x.send(null);
+               if (x.readyState == 4 && x.status == 200) {
+                   try {
+                       var html = x.responseText.createHTML();
+                       opt.description = window.Minibuffer.$X('//title', html)[0].text;
+                   } catch(e) {}
+               }
+           }
+           var request = [
+               "url=", encodeURIComponent(opt.url),
+               "&oldurl=", encodeURIComponent(opt.url),
+               "&private=", opt.private,
+               "&description=", encodeURIComponent(opt.description),
+               "&notes=", encodeURIComponent(comment),
+               "&tags=", encodeURIComponent(opt.tags),
+               "&v=", opt.v,
+               "&key=", opt.key,
+               ].join('');
+           GM_xmlhttpRequest({
+             method: 'POST',
+             url: opt.action,
+             headers: {
+                 'Content-Type': 'application/x-www-form-urlencoded'
+               },
+             onload: afterPost,
+             onerror: function(res){log('onerror',res.responseText, '\n',res.responseHeaders)},
+             data: request
+           });
+       }
+       var postToDelicious = function(nodes, urls){
+           if(!urls.length){
+               window.Minibuffer.status('bookmark'+time,'Bookmark 100 %', 1000)
+               return;
+           }
+           window.Minibuffer.status('bookmark'+time,'Bookmark ' + Math.floor((total-urls.length) / total * 100) + '%');
+           getParam(nodes.shift(), urls.shift(), post, function(){postToDelicious(nodes, urls)});
+       }
+       postToDelicious(nodes, urls);
+   };
+
 // var delicious = function(urls, tags){
 //     log('delicious: urls:tags',urls, tags);
 // }
@@ -147,7 +231,7 @@
 //     log('livedoor: urls:tags',urls, tags);
 // }
    addBookmark('hatena',    'h', hatenab);
-// addBookmark('delicious', 'd', delicious);
+   addBookmark('delicious', 'd', delicious);
 // addBookmark('livedoor',  'l', livedoorclip);
    
    window.Minibuffer.addCommand({
Posted at by