ニコニコ動画で全画面表示

現在は正常に動作しません

作ってみたら意外に便利だったので置いときます。

z キーか動画内の左上 100px の部分をクリックで全画面表示。

で動作確認済み。

2007-05-14 追記

Windows + Firefox で確認したけど z キーしか効かないみたい。
てか watch_naisho なんてあったのか…。IE しかうまく動かないみたいだから、作る意義はあったと思いたい。

2007-05-30 追記

HTML の構造が変わって動かなくなっていたのを修正。
ついでに Safari に対応するのが大変そう&誰も必要としてないらしいということで Firefox 専用に変更。

2007-06-19 追記

RC にあわせて修正。ついでにやっぱり Safari でも動くようにした。
RC になって用済みになるだろうと思ってたのに逆に naisho がなくなって悪化してる。

2007-06-25 追記

また動かなくなったと思ったら拡大ボタンついてた。Firefox かつディスプレイ縦向きの人以外は微妙だけど…。
http://blog.nicovideo.jp/2007/06/post_111.php
というわけで、このスクリプトの更新はここまで。

// ==UserScript==
// @name          Nicovideo with Full Screen
// @namespace     http://m4i.jp/
// @include       http://www.nicovideo.jp/watch/*
// @version       0.3
// ==/UserScript==

(function() {
    var w = 'undefined' == typeof unsafeWindow ? window : unsafeWindow;

    var flvplayer = w.document.getElementById('flvplayer');
    if (!flvplayer) return;

    var isFirefox = navigator.userAgent.indexOf('Firefox') > -1;

    var screenTop    = 102;
    var screenLeft   = 7;
    var screenWidth  = 540;
    var screenHeight = 386;
    var isFullScreen = false;

    var flvplayerWidth  = flvplayer.width;
    var flvplayerHeight = flvplayer.height;

    var container = flvplayer.parentNode;
    container.style.height = flvplayer.height + 'px';

    var subcontainer = w.document.createElement('div');
    container.appendChild(subcontainer);
    subcontainer.appendChild(flvplayer);
    with (subcontainer.style) {
        position = 'absolute';
        zIndex   = '10';
    }

    var button = w.document.createElement('div');
    subcontainer.appendChild(button);
    with (button.style) {
        position = 'absolute';
        zIndex   = '20';
    }

    reset();

    button.addEventListener('click', toggle, true);
    w.document.documentElement.addEventListener('keydown', function(event) {
        if (90 == event.keyCode) toggle();
    }, true);

    function toggle() {
        isFullScreen ? reset() : toFullScreen();
    }

    function reset() {
        isFullScreen = false;
        flvplayer.width  = flvplayerWidth;
        flvplayer.height = flvplayerHeight;

        with (subcontainer.style) {
            top  = '';
            left = '';
        }
        with (flvplayer.style) {
            width  = '';
            height = '';
        }
        with (button.style) {
            top    = screenTop    + 'px';
            left   = screenLeft   + 'px';
            width  = screenWidth  + 'px';
            height = screenHeight + 'px';
            cursor = 'nw-resize';
        }
    }

    function toFullScreen() {
        var rate = Math.min(
            (w.innerWidth  - 16) / screenWidth,
            (w.innerHeight - 16) / screenHeight
        );

        w.scrollTo(0, 0);
        isFullScreen = true;
        if (isFirefox) {
            flvplayer.width  = Math.floor(flvplayerWidth  * rate);
            flvplayer.height = Math.floor(flvplayerHeight * rate);
        }

        with (subcontainer.style) {
            top  = '-' + Math.floor(screenTop  * rate) + 'px';
            left = '-' + Math.floor(screenLeft * rate) + 'px';
        }
        with (flvplayer.style) {
            width  = Math.floor(flvplayerWidth  * rate) + 'px';
            height = Math.floor(flvplayerHeight * rate) + 'px';
        }
        with (button.style) {
            top    = Math.floor(screenTop    * rate) + 'px';
            left   = Math.floor(screenLeft   * rate) + 'px';
            width  = Math.floor(screenWidth  * rate) + 'px';
            height = Math.floor(screenHeight * rate) + 'px';
            cursor = 'se-resize';
        }
    }
})();