はてなハイクの投稿をまとめてダイアリーに

    @@ -1,6 +1,6 @@ /* * @title はてなハイクの投稿をまとめてダイアリーに - * @description はてなハイクの一日分の投稿をまとめてはてなダイアリーに投稿します。はてなにログインした状態で、はてなハイクで実行してください。 + * @description はてなハイクの一日分の投稿をまとめてはてなダイアリーに投稿します。はてなにログインした状態で、はてなハイクで実行してください。 (事前にコメント中に示したスタイルシートを設定しておくと、ハイクっぽく表示されます。) * @license MIT License */
  • /*
     * @title はてなハイクの投稿をまとめてダイアリーに
     * @description はてなハイクの一日分の投稿をまとめてはてなダイアリーに投稿します。はてなにログインした状態で、はてなハイクで実行してください。 (事前にコメント中に示したスタイルシートを設定しておくと、ハイクっぽく表示されます。)
     * @license MIT License
     */
    
    javascript:
    
    /* Use this style sheet to format Haiku entries appropriately in Diary/Group:
    ><style>
      .haiku-entries .haiku-entry {
        margin: 0;
        padding: 0;
      }
      .haiku-entries .haiku-entry ~ .haiku-entry {
        border-top: 1px solid #EEEEEE;
        padding-top: 0.8em;
      }
      .haiku-entry .haiku-target {
        margin: 0;
        font-size: 90%;
      }
      .haiku-entry .haiku-target a.haiku-target-link {
        padding-right: 0.3em;
        color: #467237;
        font-weight: bolder;
        text-decoration: underline;
      }
      .haiku-info {
        font-size: 80%;
        color: #999999;
      }
      .haiku-body .haiku-in-reply-to-link {
        background: url("http://h.hatena.com/images/icon-replylink.gif") no-repeat scroll 0 60% transparent;
        padding-left: 12px;
        padding-right: 0.3em;
        font-weight: bolder;
        font-size: 80%;
        color: #B36B85;
        text-decoration: none;
      }
      .haiku-entry .haiku-body div {
        display: inline;
      }
      .haiku-entry .haiku-body div p {
        margin: 0;
      }
      .haiku-entry .haiku-body div p img {
        max-width: 400px;
        max-height: 400px;
      }
      .haiku-info a {
        color: #B36B85;
        text-decoration: none;
      }
      .haiku-info .haiku-reply-link {
        background: url("http://h.hatena.com/images/icon-reply.gif") no-repeat scroll 0 60% transparent;
        padding-left: 12px;
      }
    </style><
    */
    
    var header = document.getElementById ('header-username');
    var hatenaId = header ? header.getAttribute ('data-name') : null;
    hatenaId = hatenaId || 'my';
    // hatenaId = prompt ('hatenaId', hatenaId);
    
    var date = new Date ();
    date.setTime (date.getTime () - 12 * 60 * 60 * 1000);
    var m = date.getMonth () + 1; if (m < 10) m = '0' + m;
    var d = date.getDate (); if (d < 10) d = '0' + d;
    date = date.getFullYear () + '-' + m + '-' + d;
    
    var xhr = new XMLHttpRequest ();
    xhr.open ('GET', '/' + hatenaId + '/activities.json?per_page=100&date=' + date, true);
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        if (xhr.status < 300) {
          processData (JSON.parse (xhr.responseText));
        }
      }
    };
    xhr.send (null);
    void (0);
    
    function processData (data) {
      var entries = [];
      var haikuDomain = location.hostname;
      for (var i = 0; i < data.items.length; i++) {
        var item = data.items[i];
        var container = document.createElement ('div');
        // Use "a" in "h3" to enable Hatena Star in Hatena Diary/Group
        container.innerHTML = '<div class="haiku-entry section"><h3 class=haiku-target><a></a><a href="" class=haiku-target-link>_</a></h3><div class=haiku-body><a class=haiku-in-reply-to-link>_</a><div>_</div></div><div class=haiku-info><a class=haiku-time>_</a> from <a class=haiku-source>_</a> <a class=haiku-reply-link>Reply</a></div></div>';
        var haikuEntry = container.firstChild;
        var haikuTarget = haikuEntry.firstChild;
        haikuTarget.firstChild.href = item.star_url;
        haikuTarget.lastChild.href = 'http://' + haikuDomain + '/' + item.target.url_name + '/';
        haikuTarget.lastChild.title = item.target.url_name;
        haikuTarget.lastChild.firstChild.data = item.target.display_name;
        var haikuBody = haikuEntry.childNodes[1];
        if (item.reply_to_eid) {
          haikuBody.firstChild.href = 'http://' + haikuDomain + '/' + item.reply_to_author.url_name + '/' + item.reply_to_eid;
          haikuBody.firstChild.firstChild.data = item.reply_to_author.display_name;
        } else {
          haikuBody.removeChild (haikuBody.firstChild);
        }
        haikuBody.lastChild.firstChild.data = item.body_haiku_text.replace (/\bhttps?:\/\/[\x21-\x7E]+\.(?:jpe?g|png|gif)\b/gi, function (u) {
          return '[' + u + ':image]';
        }).replace (/\[\[([^\[\]]+)\]\]/g, function (_, k) { return '[h:keyword:' + k + ']' });
        var haikuInfo = haikuEntry.lastChild;
        var date = new Date (item.created_on * 1000);
        haikuInfo.firstChild.firstChild.data = date.toLocaleString ();
        haikuInfo.firstChild.href = item.star_url;
        haikuInfo.childNodes[2].firstChild.data = item.source_target.display_name;
        haikuInfo.childNodes[2].href = 'http://' + haikuDomain + '/' + item.source_target.url_name + '/';
        haikuInfo.childNodes[4].href = item.star_url;
        entries.push (container.innerHTML);
      }
      var string = '<div class=haiku-entries>' + entries.join ("\n") + '</div>';
      editInDiary (string);
    } // processData
    
    function editInDiary (text) {
      var form = document.createElement ('form');
      form.method = 'post';
      form.action = 'http://d.hatena.ne.jp/refer';
    
      var input = document.createElement ('input');
      input.type = 'hidden';
      input.name = 'appendbody';
      input.value = text;
    
      form.appendChild (input);
      document.body.appendChild (form);
      form.submit ();
    } // editInDiary
    
    /*
    
    Copyright 2012 Wakaba <w@suika.fam.cx>.
    
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    
    */
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2012/02/11 01:55:24 - 2012-02-11
  2. 2012/02/11 01:54:42 - 2012-02-11