/* * ==VimperatorPlugin== * @name youtubeamp.js * @description this script gives you keyboard oprations for YouTube.com. * @description-ja YouTube のプレーヤーをキーボードで操作できるようにする。 * @author janus_wel * @version 0.12 * @minversion 2.0pre 2008/10/16 * ==/VimperatorPlugin== * * LICENSE * New BSD License * * USAGE * :ytinfo * プレーヤーに関しての情報を表示する。今のところバージョンだけ。 * :ytpause * 再生 / 一時停止を切り替える。 * :ytmute * 音声あり / なしを切り替える。 * :ytsize * 最大化 / ノーマルを切り替える。動いてない。 * :ytseek [position] * 指定した場所にシークする。秒数で指定が可能。 * 指定なしの場合一番最初にシークする。 * :ytseek! delta * 現在の位置から delta 分離れた所にシークする。秒数で指定が可能。 * マイナスを指定すると戻る。指定なしの場合変化しない。 * :ytvolume [volume] * ボリュームを設定する。 0 ~ 100 が指定できる。 * 指定なしの場合 100 にセットする。 * :ytvolume! delta * ボリュームを現在の値から変更する。 -100 ~ +100 を指定可能。 * 指定なしの場合変化しない。 * * SEE ALSO * http://code.google.com/apis/youtube/js_api_reference.html * * HISTORY * 2008/10/07 ver. 0.10 - initial written. * */ (function() { Function.prototype.bind = function(object) { var __method = this; return function() { return __method.apply(object, arguments); }; }; // class definition // YouTubePlayerController Class function YouTubePlayerController() { this.initialize.apply(this, arguments); } YouTubePlayerController.prototype = { initialize: function() { this.fuller = this._changeToFull.bind(this); }, constants: { VERSION: '0.12', CARDINAL_NUMBER: 10, YOUTUBE_DOMAIN: '.youtube.jp', YOUTUBE_URL: '^http://[^.]+\\.youtube\\.com/', WATCH_URL: 'http://[^.]+\\.youtube\\.com/watch', WATCH_PAGE: 1, PLAYER_NODE_ID: 'movie_player', STATE_PLAYING: 1, SIZE_WIDTH_DEFAULT: 480, SIZE_HEIGHT_DEFAULT: 385, NAME_PLAYER_VERSION: 'PLAYER_VERSION', SEEKTO_DEFAULT: 0, SEEKBY_DEFAULT: 0, VOLUMETO_DEFAULT: 100, VOLUMEBY_DEFAULT: 0, HIDE_NODES: [ 'old-masthead', 'watch-vid-title', 'watch-other-vids', 'old-footer', 'copyright', 'watch-main-area', 'watch-comments-stats', 'watch-video-response', 'chrome-promo', 'watch-video-quality-setting', ], }, getControllerVersion: function() { return this.constants.VERSION; }, pagecheck: function() { if(this.getURL().match(this.constants.WATCH_URL)) return this.constants.WATCH_PAGE; throw new Error('current tab is not watch page on youtube.com'); }, getURL: function() { return liberator.modules.buffer.URL; }, _player: function() { if(this.pagecheck() === this.constants.WATCH_PAGE) { let player = this._getElementById(this.constants.PLAYER_NODE_ID); if(! player) throw new Error('player is not found'); return player; } return null; }, togglePlay: function() { var p = this._player(); (p.getPlayerState() !== this.constants.STATE_PLAYING) ? p.playVideo() : p.pauseVideo(); }, toggleMute: function() { var p = this._player(); p.isMuted() ? p.unMute() : p.mute(); }, toggleSize: function() { var p = this._player(); (p.width == this.constants.SIZE_WIDTH_DEFAULT && p.height == this.constants.SIZE_HEIGHT_DEFAULT) ? this._fullSize() : this._normalSize(); }, _changeToFull: function() { var p = this._player(); setTimeout(function() { p.width = content.innerWidth; p.height = content.innerHeight; }, 0); }, _getElementById: function(id) { var e = window.content.document.getElementById(id); if(!e) return null; return e.wrappedJSObject ? e.wrappedJSObject : e; }, _fullSize: function() { var b = this._getElementById('baseDiv'); this.defMargin = b.style.margin; this.defPadding = b.style.padding; this.defWidth = b.style.width; b.style.margin = 0; b.style.padding = 0; b.style.width = '100%'; for(let i=0, max=this.constants.HIDE_NODES.length ; i 1) ? args.arguments[0].toString() : args.string; special ? controller.seekBy(arg) : controller.seekTo(arg); } catch(e) { liberator.echoerr(e); } }, { bang: true, } ); liberator.modules.commands.addUserCommand( ['ytvolume'], 'controll volume', function(args, special) { try { let arg = (args.arguments.length > 1) ? args.arguments[0].toString() : args.string; special ? controller.volumeBy(arg) : controller.volumeTo(arg); } catch(e) { liberator.echoerr(e); } }, { bang: true, } ); liberator.modules.commands.addUserCommand( ['ytsize'], 'toggle video size', function() { try { controller.toggleSize(); } catch(e) { liberator.echoerr(e); } }, {} ); })() // vim: set sw=4 ts=4 et; 'n181' href='#n181'>181
/*** BEGIN LICENSE BLOCK {{{
  Copyright (c) 2009 suVene<suvene@zeromemory.info>

  distributable under the terms of an MIT-style license.
  http://www.opensource.jp/licenses/mit-license.html
}}}  END LICENSE BLOCK ***/
// PLUGIN_INFO//{{{
var PLUGIN_INFO =
<VimperatorPlugin>
  <name>{NAME}</name>
  <description>Allows you to resize textareas.</description>
  <description lang="ja">テキストエリアをリサイズ可能にする</description>
  <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
  <version>0.2.1</version>
  <license>MIT</license>
  <minVersion>2.0pre</minVersion>
  <maxVersion>2.0α2</maxVersion>
  <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/resizable_textarea.js</updateURL>
  <detail><![CDATA[
== Usage ==
=== NORMAL MODE or VISUAL MODE or CARET MODE ===
>||
:textareaResize or :tr
||<
you can resize textareas by using a mouse.

=== INSERT MODE or TEXTAREA MODE ===
>||
"<A-r>" or "<M-r>"
||<
you can resize current component by using a keyboad.
=== keymap ===
"k" or "up":
  height more small.
"j" or "down":
  height more large.
"h" or "left":
  width more small.
"l" or "right":
  width more large.
"escape" or "enter":
  end of resize.
  ]]></detail>
</VimperatorPlugin>;
//}}}
(function() {

var TextResizer = function() {
  this.initialize.apply(this, arguments);
};
TextResizer.prototype = {
  initialize: function(doc) {
    this.doc = doc;
    this.handler = {
      initResize: this._bind(this, this.initResize),
      resize: this._bind(this, this.resize),
      stopResize: this._bind(this, this.stopResize),
      currentResize: this._bind(this, this.currentResize)
    };
  },
  resizable: function(focused) {
    if (focused) {
      this.initResize({ target: focused }, focused);
      return;
    }
    this.changeCursor(false);
    this.doc.addEventListener("mousedown", this.handler.initResize, false);
  },
  initResize: function(event, focused) {
    var target = this.target = event.target;
    if (!target ||
        (target.nodeName.toLowerCase() != "textarea" &&
         (target.nodeName.toLowerCase() != "input" || target.type != "text")))
      return;

    if (focused) {
      this.target.startBgColor = this.target.style.backgroundColor;
      this.target.style.backgroundColor = "#F4BC14";
      this.doc.addEventListener("keydown", this.handler.currentResize, false);
      return;
    }

    this.target.startWidth = this.target.clientWidth;
    this.target.startHeight = this.target.clientHeight;
    this.target.startX = event.clientX || event.target.offsetLeft;
    this.target.startY = event.clientY || event.target.offsetTop;

    this.doc.addEventListener("mousemove", this.handler.resize, false);
    this.doc.addEventListener("mouseup", this.handler.stopResize, false);

    try{
      event.preventDefault();
    } catch (e) {}
  },
  resize: function(event) {
    try{
      this.target.style.width = event.clientX - this.target.startX + this.target.startWidth + "px";
    } catch (e) {}

    if (this.target.nodeName.toLowerCase() == "textarea")
      this.target.style.height = event.clientY - this.target.startY + this.target.startHeight + "px";
  },
  stopResize:function(event) {
    this.doc.removeEventListener("mousedown", this.handler.initResize, false);
    this.doc.removeEventListener("mousemove", this.handler.resize, false);
    setTimeout(function(self) self.doc.removeEventListener("mouseup", self.handler.stopResize, false), 10, this);
    this.changeCursor(true);
  },
  changeCursor: function(normal) {
    for (let [,elem] in Iterator(this.doc.getElementsByTagName("textarea")))
      elem.style.cursor = normal ? "text" : "se-resize";

    for (let [,elem] in Iterator(this.doc.getElementsByTagName("input"))) {
      if (elem.type == "text")
        elem.style.cursor = normal ? "text" : "e-resize";
    }
  },
  currentResize: function(event) {
    var nodeName = this.target.nodeName.toLowerCase();
    switch (event.keyCode) {
    case KeyEvent.DOM_VK_UP: case KeyEvent.DOM_VK_K:
      if (nodeName == "textarea")
        this.target.style.height = this.target.offsetHeight - 10 + "px";
      break;
    case KeyEvent.DOM_VK_DOWN: case KeyEvent.DOM_VK_J:
      if (nodeName == "textarea")
        this.target.style.height = this.target.offsetHeight + 10 + "px";
      break;
    case KeyEvent.DOM_VK_LEFT: case KeyEvent.DOM_VK_H:
       this.target.style.width = this.target.offsetWidth - 10 + "px";
      break;
    case KeyEvent.DOM_VK_RIGHT: case KeyEvent.DOM_VK_L:
      this.target.style.width = this.target.offsetWidth + 10 + "px";
      break;
    case KeyEvent.DOM_VK_RETURN: case KeyEvent.DOM_VK_ENTER: case KeyEvent.DOM_VK_ESCAPE:
      this.target.style.background = this.target.startBgColor;
      setTimeout(function(self) {
          self.doc.removeEventListener("keydown", self.handler.currentResize, false);
          self.target.focus();
        }, 10, this
      );
      break;
    }
    try{
      event.preventDefault();
    } catch (e) {}
  },
  _bind: function() {
      var obj = Array.prototype.shift.apply(arguments);
      var func = Array.prototype.shift.apply(arguments);
      var args = [];
      for (let i = 0, len = arguments.length; i < len; args.push(arguments[i++]));
      return function(event) {
        return func.apply(obj, [ event ].concat(args));
      };
  }
};

commands.addUserCommand(
  [ "textareaResize", "tr" ], "Allows you to resize textareas.",
  function() {
    var instance = new TextResizer(window.content.document);
    instance.resizable.apply(instance);
  },
  null,
  true
);

mappings.add(
  [ modes.INSERT, modes.TEXTAREA ],
  [ "<M-r>", "<A-r>" ],
  "Allows you to resize current textarea.",
  function() {
    var instance = new TextResizer(window.content.document);
    instance.resizable.apply(instance, [ document.commandDispatcher.focusedElement ]);
  }
);

})();
// vim: set fdm=marker sw=2 ts=2 sts=0 et: