ニコニコ動画で見た映像をtwitterに送るGreasemonkeyスクリプト

koyachiの日記 - youtubeで見た映像をtwitterに送るGreasemonkeyスクリプトをただニコニコ動画用に変えただけ。

// ==UserScript==
// @name           niconico report to twitter.
// @namespace      http://d.hatena.ne.jp/jazzanova/
// @include        http://www.nicovideo.jp/watch/*
// ==/UserScript==

(function() {
  var w = (typeof unsafeWindow == "undefined") ? window : unsafeWindow;
  with (w) {
    function post_twitter(status){
      GM_xmlhttpRequest({
        method : 'POST',
        url: 'http://twitter.com/statuses/update.json',
        headers: {
            'Content-type': 'application/x-www-form-urlencoded',
        },
        data   : 'status=' + status,
        onload : function(res) {
          GM_log('twittered!');
        },
        onerror: function(res) {
          var err = 'Failed - ' + res.status + ': ' + res.statusText;
          GM_log(err);
        },
      });
    }
    setTimeout(function(){
      var url = document.location.href;
      var title = document.title;
      post_twitter(encodeURIComponent(['Watching: "', title, '" ', url].join('')));
    }, 60 * 1000);
  }
})();