2008/01/31


以前、個人的なブームでPlaggerのPublish::XXXプラグインを作ってた頃の知識を再利用。

Minibufferには、ソーシャルブックマークへ登録するコマンド「bookmark」があります。
minibufferbookmarkcommand.user.js
ちょっと前これを色んなSBMに対応出来る様にプラガブルに修正したのですが、ノウハウを生かして以下2本のbookmarkプラグインを作成しました。

GooBookmarkプラグイン
minibufferbookmarkcommand.goobookmark.user.js
NiftyClipプラグイン
minibufferbookmarkcommand.niftyclip.user.js
それぞれ :bookmark -g
:bookmark -n
で実行出来る様になっています。
Publish::XXXの時と同様に利用している人は皆無かと思いますが、よかったらどうぞ。
Posted at by




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




もう眠くなってきたら :shutdown ソースは // ==UserScript==
// @name           Minibuffer Shutdown Command
// @namespace      Minibuffer.Shutdown.Command
// @include        http://*
// ==/UserScript==


(function(){
  var mes = [
    'System is going down for system shutdown now.......',
    'Starting local stop scripts.                       ',
    'Exiting Syslogd!                                   ',
    'Syncing all filesystems:                       [OK]',
    'Unmounting all filesystems:                    [OK]',
    'The system is going down NOW !!                    ',
    'Sending SIGTERM to all processes.                  ',
    'The system is halted. Press Reset or turn off power',
    'flushing ide devices:                          [OK]',
    'System halted.                                     ',
  ];
  function shutdown( stdin ) {
    GM_addStyle(<><![CDATA[
      #gm_minibuffer_flash_status * {
      font-family: 'terminal', 'monospace';
      font-weight: bold;
      }
      ]]></>);
    var n = 0;
    var timer = setInterval(function(){
      window.Minibuffer.status('shutdown'+n, mes[n], 50000);
      if (n++ >= mes.length) {
        clearInterval(timer);
        document.open();
        document.close();
        document.body.style.backgroundColor='black';
      }
    }, 1000);
    return stdin;
  }

  if (typeof window.Minibuffer != 'undefined') {
    window.Minibuffer.addCommand({
      name: "shutdown",
      command: shutdown,
    });
  }
})();
こんな感じ。
インストール:minibuffer.shutdown.user.js
てか実用的な物つくれ!俺
Posted at by