diff options
author | anekos | 2014-06-20 23:38:08 +0900 |
---|---|---|
committer | anekos | 2014-06-20 23:38:08 +0900 |
commit | 4efa78ddfd67e9d6fc3e44124b40daf913fc5b99 (patch) | |
tree | c820ed45c18baff637d0619f24f54dd6f27415ba /youtubeamp.js | |
parent | 3e79adadc38edc50e92323cbb1cfc85d171e9e1f (diff) | |
parent | 53f88cb3f394a0b6278f8205b8f142c42f01ea0e (diff) | |
download | vimperator-plugins-4efa78ddfd67e9d6fc3e44124b40daf913fc5b99.tar.bz2 |
Merge pull request #59 from oniatsu/youtubeamp/enable-seek-by-percentage
youtubeamp: Enable seek by percentage
Diffstat (limited to 'youtubeamp.js')
-rw-r--r-- | youtubeamp.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/youtubeamp.js b/youtubeamp.js index f2c6125..2f89c16 100644 --- a/youtubeamp.js +++ b/youtubeamp.js @@ -192,8 +192,14 @@ YouTubePlayerController.prototype = { }, seekTo: function(position) { + var p = this._player(); + if(position) { - if(position.match(/^(\d+):(\d+)$/)) { + if(position.match(/^(\d+)%$/)) { + var duration = p.getDuration(); + position = parseInt((duration * RegExp.$1 / 100), this.constants.CARDINAL_NUMBER); + } + else if(position.match(/^(\d+):(\d+)$/)) { position = parseInt(RegExp.$1, this.constants.CARDINAL_NUMBER) * 60 + parseInt(RegExp.$2, this.constants.CARDINAL_NUMBER); } @@ -201,17 +207,22 @@ YouTubePlayerController.prototype = { } else position = this.constants.SEEKTO_DEFAULT; - var p = this._player(); p.seekTo(position); }, seekBy: function(delta) { + var p = this._player(); + if(delta) { + if(delta.match(/^([-+]?)(\d+)%$/)) { + var duration = p.getDuration(); + delta = parseInt((duration * RegExp.$2 / 100), this.constants.CARDINAL_NUMBER); + if(RegExp.$1 == '-') delta = -delta; + } if(isNaN(delta)) throw new Error('assign signed number : seekBy()'); } else delta = this.constants.SEEKBY_DEFAULT; - var p = this._player(); var position = p.getCurrentTime(); position += parseInt(delta, this.constants.CARDINAL_NUMBER); |