雑記

2009年11月2日月曜日

Greasemonkeyでニコニコ動画のマイリスト追加時にTwitterにつぶやいてみる ~その2 ニコニコ動画(9)~

ニコニコ動画がバージョンアップしてニコニコ動画(9)なってたので、取り急ぎマイリススクリプトもかきかえてみた。あまりキレイなコードではないけど。
 マイリス登録が何故かポップアップになっていたので、「ユーザースクリプトを実行するページ」を

・http://www.nicovideo.jp/mylist_add/video/*


に変更。というか正直個人的にはポップアップはやめていただきたいなぁ・・・。
そして「ひとことコメント入力」も追加されたので、これにも後で対応したいかなと。
 「とりあえず 一発登録」って機能追加されてるけど、よっぽどマイリスト使いこなせない人が多いのか。まぁ自分も人のこと言えたほどじゃないけど。

2009/11/11 ひとことコメントも一緒につぶやくようにちょっとだけ修正しました。

// ==UserScript==
// @name mylismylis
// @description Post niconicodouga mylist to Twitter
// @author sakky
// @namespace http://unslash.blogspot.com/
// @include http://www.nicovideo.jp/mylist_add/video/*
// ==/UserScript==

(function () {
    var mform = document.getElementById('box_mylist_add');

    var twit = function(){
        var url = 'http://twitter.com/statuses/update.json';

        var title = document.getElementsByTagName('h3')[0].innerHTML;
        var mylisthref = 'http://www.nicovideo.jp/watch/' + document.getElementsByName('item_id')[0].value;
        var mselect = document.getElementById('select_group');
        var mname = mselect.options[mselect.selectedIndex].text;
        var comment = document.getElementById('edit_description').value;

        var hitokoto = '';
        if (comment.length > 0) hitokoto = 'ひとこと:' + comment;

        GM_xmlhttpRequest({
            method : 'POST',
            url : url,
            headers: {'Content-type': 'application/x-www-form-urlencoded',},
            data : 'status=' + encodeURIComponent('マイリス追加:' + mname + '[' + title + mylisthref) + '] '+ hitokoto,
            onload : function(res){ message('Updated!');},
            onerror: function(res){ message('Failed to update' + res.status + ':' + res.statusText);},
        });
    }

    mform.elements[4].addEventListener('click', twit, true);
})();

0 件のコメント: