あぁ〜半年に一度の定期健診が近づいてきた。

また、弘前の病院までいかなきゃならない(金曜日)。この時期になると必ずといっていいほど、咳き込むようになる。そして検診を終えると、嘘のように治る。
ところが今回は、頭が割れるように痛い。風邪気味なのだろうか?処方してもらった薬ではないが、炎症を抑える薬を飲んでいる。そして最近ぼぉ〜としている。

なにげに、JavaScript++かも日記からajax のライブラリーを落とそうとしたら、落とせない!しかもクロムかサファリで!となっていたので、クロムを入れて見た。速そうだけど、

<script type="application/javascript; version=1.8">

では、動かないのね。しかし結局、落とせなかった。で困り果て、自分用に書くことにした。そこの古いものを参考にしているので、「パクリ」だと思われてもしょうがないかな。
ついでに、クッキーも書き直した。それにしても頭が痛い。

Ajax

(function () {
  if ('undefined' === typeof XMLHttpRequest)
    this.XMLHttpRequest =
      (function () {
        for (var i = 0, h; h = arguments[i++];)
          try { h (); return h; } catch (err) { ; }
        return null;
      })(function () { return new ActiveXObject ('Msxml2.XMLHTTP.6.0') },
         function () { return new ActiveXObject ('Msxml2.XMLHTTP.3.0') });
  

  var obj2str =
    (function (obj) {
      var p = [];
      var i, I, k, q;

      switch (typeof obj) {
      case 'string' :
        obj = obj.split ('\u0026');
        for (i = 0, I = obj.length; i < I; i++) {
          if (q = obj[i]) {
            k = q.split ('=');
            p.push (encodeURIComponent (k[0]) + '=' + encodeURIComponent (k[1]));
          }
        }
        return (p.length) ? '\u0026' + p.join ('\u0026'): '';
      
      case 'object' :
        for (i in obj) {
          if (obj.hasOwnProperty (i))
            p.push (encodeURIComponent (i) + '=' + encodeURIComponent (obj[i]));
        }
        return (p.length) ? '\u0026' + p.join ('\u0026'): '';
      }
    });


  var ajax =
    (function (uri, method, parameter, callbackfn, callbackobj) {
      var httpObj;
      var para;

      if (httpObj = new XMLHttpRequest) {
        para = 'SendTime=' + (new Date).getTime() + obj2str (parameter);
        
        if ('GET' === method.toUpperCase ())
          uri += '?' + para;

        httpObj.open (method, uri, true);
        httpObj.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        httpObj.onreadystatechange =
          function () {
            if (4 === httpObj.readyState) {
              try {
                if (200 === httpObj.status)
                  callbackfn.call (callbackobj, httpObj.responseText);
              }
              catch (err) { ; }

              httpObj.onreadystatechange = new Function;
              uri = method = parameter = callbackfn = callbackobj = httpObj = para = null;
            }
          };

        httpObj.send (para);
      }
    });
  

  this.ajax = ajax;
})();


クッキー

(function () {

  var get =
    (function () {
      if (arguments.length)
        return (function (name) {
          var doc = this.document || document;
          var n = encodeURIComponent (name).replace (/([.*()])/g, '\\$1');
          var v = doc.cookie.match (RegExp (n + '\\s*=\\s*(.*?)(?:[\\s;,]|$)'));
          return v ? decodeURIComponent (v[1]): '';
        }).apply (this, arguments);

      return false;
    });


  var set =
    (function () {
      if (1 < arguments.length)
        return (function (name, value, day, path, domain) {
          var d = this.document || document;
          var t = new Date;

          t.setDate (t.getDate () + (day || 0));
          d.cookie = encodeURIComponent (name) + '=' + encodeURIComponent (value) + ';' +
            'expires=' + t.toUTCString () + ';' +
            (path ? 'path=' + encodeURIComponent (path) + ';': '') +
            (domain ? 'domain=' + encodeURIComponent (domain) + ';': '');

          return true;
        }).apply (this, arguments);

      return false;
    });
  
  var update =
    (function () {
      return function (name, day, path, domain) {
        var val = get.call (this, name);
        set.call (this, name, val, day, path, domain);
      }.apply (this, arguments)
    });
  
  this.getCookie = get;
  this.setCookie = set;
  this.updateCookie = update;
})();