// ==UserScript==
// @name           niconico scroll to video
// @namespace      http://www.pshared.net/
// @description    ニコニコ動画の動画が一画面に収まる位置にスクロールします。
// @include        http://www.nicovideo.jp/watch/*
// ==/UserScript==

(function() {
    function scroll() {
        var id = window.outerHeight < 1000 ? 'video_tags' : 'WATCHHEADER';
        var offsetTop = document.getElementById(id).offsetTop;
        window.scrollTo(0, offsetTop);
    }

    window.addEventListener('load', function() {
        var nodes = document.getElementsByClassName('ads_728');
        if (nodes.length > 0) {
            var node = nodes[0];
            var parent = node.parentNode;
            parent.removeChild(node);
        }

        scroll();
    }, false);

    var ignore = /input|textarea/i;
    document.addEventListener('keypress', function(e) {
        if(ignore.test(e.target.tagName)) {
            return;
        }

        if (e.charCode == 114) { // 'r'
            scroll();
        }
    }, false);
})();

