diff options
author | oniatsu | 2014-04-30 14:26:47 +0900 |
---|---|---|
committer | oniatsu | 2014-04-30 14:26:47 +0900 |
commit | 53f88cb3f394a0b6278f8205b8f142c42f01ea0e (patch) | |
tree | 5bfddc959487faf2210bfc604639c35523735a47 /youtubeamp.js | |
parent | d936e2f7b2b0bdb6f05860b35ccc1f23aca68cdb (diff) | |
download | vimperator-plugins-53f88cb3f394a0b6278f8205b8f142c42f01ea0e.tar.bz2 |
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 1ab8833..5043f5e 100644 --- a/youtubeamp.js +++ b/youtubeamp.js @@ -197,8 +197,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); } @@ -206,17 +212,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); |