Skip to content

Instantly share code, notes, and snippets.

@abcang
Created June 25, 2016 09:09
Show Gist options
  • Save abcang/ad13b030c4b1d52b9a773d7faaf8187f to your computer and use it in GitHub Desktop.
Save abcang/ad13b030c4b1d52b9a773d7faaf8187f to your computer and use it in GitHub Desktop.
ニコニコの動画を矢印キーで数秒進めたり戻したりできるやつ
// ==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);
})();
@abcang
Copy link
Author

abcang commented Jun 25, 2016

コメント入力中にも動作するので注意

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment