Created
June 25, 2016 09:09
-
-
Save abcang/ad13b030c4b1d52b9a773d7faaf8187f to your computer and use it in GitHub Desktop.
ニコニコの動画を矢印キーで数秒進めたり戻したりできるやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Niconico move frame | |
// @namespace https://abcang.net/ | |
// @version 0.1 | |
// @description move frame on niconico video to press arrow key | |
// @author ABCanG | |
// @match http://www.nicovideo.jp/watch/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function Player() { | |
this.player = document.getElementById('external_nicoplayer'); | |
this.nextTime = 15; | |
this.prevTime = 10; | |
this.player.addEventListener('keydown', function(e) { | |
if (e.keyCode == 39) { | |
this.nextFrame(); | |
} else if(e.keyCode == 37) { | |
this.prevFrame(); | |
} | |
}.bind(this)); | |
} | |
Player.prototype.nextFrame = function() { | |
var playtime = this.player.ext_getPlayheadTime(); | |
var totalTime = this.player.ext_getTotalTime(); | |
var next = Math.min(playtime + this.nextTime, totalTime); | |
this.player.ext_setPlayheadTime(next); | |
}; | |
Player.prototype.prevFrame = function() { | |
var playtime = this.player.ext_getPlayheadTime(); | |
var prev = Math.max(playtime - this.prevTime, 0); | |
this.player.ext_setPlayheadTime(prev); | |
}; | |
window.addEventListener('load', (function() { | |
var player = new Player(); | |
})(), false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コメント入力中にも動作するので注意