# nlフィルタ定義(文字コード判定用なのでこの行は削除しないこと)
# 2017/05/14
# 2017/05/21 dblclickイベントに変更

[Script]
Name = 動画ダブルクリックでフルスクリーン(watchページ HTML5)
URL = www\.nicovideo\.jp/watch/
Require = "js-initial-watch-data"
Append<
window.addEventListener("load", function() {
var onDoubleClick = function(ret) {
  // ダブルクリック -> フルスクリーンかどうかによって分岐
  var videoContainer = document.getElementsByClassName("VideoContainer")[0];
  if (videoContainer.classList.contains("is-fullscreen")) {
    // フルスクリーン -> Escapeキーで通常状態に戻す
    ret.keycode = 0x1b;
    ret.key = "Escape";
    ret.press = false;
  } else {
    // 通常状態 -> Fキーでフルスクリーンに
    ret.keycode = 0x46;
    ret.key = "f";
    ret.press = true;
  }
  return true;
};

var videoPlayer = document.getElementById("VideoPlayer");
videoPlayer.addEventListener("dblclick", function(e) {
  var t = {};
  onDoubleClick(t);
  ["keydown", "keypress", "keyup"].forEach(function(evname) {
    var event;
    if (evname == "keypress" && !t.press) return;
    if (typeof KeyboardEvent === "function") {
      // Chrome, Firefox, Edge
      event = new KeyboardEvent(evname, {bubbles: true, key: t.key, keyCode: t.keycode, which: t.keycode});
    } else {
      // IE
      event = document.createEvent("KeyboardEvent");
      event.initKeyboardEvent(evname, true, false, window, t.key, 0, "", false, ""); 
    }
    // Chrome, IE Hack: http://stackoverflow.com/questions/10455626/keydown-simulation-in-chrome-fires-normally-but-not-the-correct-key
    Object.defineProperty(event, 'keyCode', { get: function() { return t.keycode; } });
    Object.defineProperty(event, 'which', { get: function() { return t.keycode; } });
    this.dispatchEvent(event);
  }.bind(this));
}); });
>

