Subscribed unsubscribe Subscribe Subscribe

Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

YouTube のタグによる検索結果の feed アイコンを表示する Greasemonkey スクリプト

YouTube greasemonkey

YouTube てば最高なんだけど、検索結果の feed ないの?なんで!とか思ってた。ページのいちばん下にある RSS アイコンをクリックしても説明ページが出てくるだけだし。「[戯] YouTube でタグによる RSS フィードを取得するには」を読んでそれが早とちりであることを知った。。

YouTube では最近人気の動画の RSS フィードを配信していますが,タグによる RSS フィードも取得できることが分かりました.

つわけで、以下のようなフォーマットになってるとのこと。

(feed|http)://www.youtube.com/rss/tag/tag1+tag2+tag3.rss

YouTube の説明には書かれてなかったけど、タグを複数指定する場合は "+ (%2B)" でタグをつないでやればいいみたい。以上、説明はちゃんと読みましょうね!というお話でした!!!
……ってんでは面白くもなんともないので、YouTube のタグによる検索結果の feed アイコンを表示する Greasemonkey スクリプトを書いてみました。日本語のタグもいけます。
インストール: youtube_add_feed_icon.user.js

// ==UserScript==
// @name          Add Feed Icon for YouTube Search Result
// @namespace     http://antipop.gs/ns/greasemonkey/youtube_add_feed_icon
// @include       *youtube.com/results*
// @include       *youtube.com/watch*
// ==/UserScript==

(function(){
    var $  = function (id)  { return document.getElementById(id); };
    var $C = function (tag) { return document.createElement(tag); };

    var input    = $('searchField');
    var keywords = encodeURIComponent(input.value.split(' ').join('+'));

    if (keywords == '') return;

    var feed = $C('a');
    with (feed) {
        id   = 'feed';
        href = ['http://www.youtube.com/rss/tag/', keywords, '.rss'].join('');
    }
    var feedIcon = $C('img');
    with (feedIcon) {
        id  = 'feed_icon';
        src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAANbY1E9YMgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFWUExURfSRNut%2FMvudOvqcOfiZOf%2F58%2FKNNfaUN%2BZ%2FM%2BmFNeZ0L%2B6FNOh5MfCJN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MkV3%2FgSDMKNZ927y%2F%2FzY%2FUqZGfB6CdbQ5tSNSNPb9dFQDhwrbuo84wP7MC9Cy7RRK9i9r23vUgA2zobq5NEc%2BO1SFM8CfQVjklRX4nHY%2FXIMwaBfwocoUke%2B8ug9%2BxD2RlNUpxV%2F9grrdewySXxWkxQNX%2BJ%2FBoHGFK%2BcJhokXBwY2AJX0ZL%2FIa9sNJyjn413drb%2FpWPX%2FYKpeIpe0%2FnCKrxUS4vMDIZHXJJ7ZTlWiglSwx80%2BAAQCPUTbYfKCEOAAAAABJRU5ErkJggg%3D%3D';
        with (style) {
            marginRight   = '0.5em';
            verticalAlign = 'middle';
            border        = 'none';
        }
    }
    feed.appendChild(feedIcon);

    $('searchForm').insertBefore(feed, input);
})();