Warning: fopen(/www/sites/update.greasyfork.icu/index/store/temp/d71733ebd71a82220276b42881343314.js): failed to open stream: No space left on device in /www/sites/update.greasyfork.icu/index/scriptControl.php on line 65
// ==UserScript== // @name Niconico My Theater // @namespace knoa.jp // @description 自分のPC内の動画ファイルと差し替えてニコニコできます。 // @include https://www.nicovideo.jp/watch/* // @version 1.1.1.1 // @grant none // @downloadURL https://update.greasyfork.icu/scripts/373548/Niconico%20My%20Theater.user.js // @updateURL https://update.greasyfork.icu/scripts/373548/Niconico%20My%20Theater.meta.js // ==/UserScript== (function(){ const SCRIPTNAME = 'NiconicoMyTheater'; const DEBUG = false;/* [update] 1.1.1.1 動作確認。 * 機能: ニコニコに投稿された動画を、自分のPC内の動画ファイルに差し替えてニコニコできます。 [Shift+左右] で1秒送りなど、快適なコメント投稿のためのショートカットキーを追加します。※ フルスクリーン時は、コメント欄にフォーカスしていても、しばらく操作がなければコントローラを消します。※ ※いずれも、動画ファイルを差し替えなくても有効です。 動画の差し替え方: ブラウザで再生できる動画ファイル(.mp4, .m4v など)をご用意ください。 動画プレイヤーの設定ボタン(歯車)の左隣に、ファイルと差し替えるボタンが現れます。 再生時刻が元の動画とズレている場合は、秒単位でプラスマイナス調整できます。 追加のショートカットキー: [Enter]: 再生停止(フォーカスはコメント欄へ) [左右]: 10秒移動(空欄ならコメント欄でも機能します) [Shift+左右]: 1秒移動(空欄ならコメント欄でも機能します) [再生時刻クリック]: 指定時刻にジャンプ # ニコニコ標準のショートカットキー おすすめの楽しみ方: 1. 再生したままコメントするスタイル: コメ欄フォーカスのまま視聴中、フルスクリーン時はしばらくするとコメ欄は邪魔にならないように消えるが、入力開始すると自動でコメ欄が表示され、[Enter] で送信、またしばらくするとコメ欄は消える。 2. 毎回停止してコメントするスタイル: 視聴中に Enter で停止してコメ欄フォーカス、 [左右][Shift+左右] で時刻を微調整でき、コメ入力して [Enter] で送信すると、再生が再開される。 3. 自分の感想をまとめてから一括して投稿するスタイル: ニコニコ動画のコメントをまとめて投稿するブックマークレット をご活用ください。 # SZBH方式とは (エスゼットビーエイチホウシキとは) [単語記事] - ニコニコ大百科 動作確認: Windows/MacのChromeで確認しています。 一部のブラウザでは動作が重い場合があるようです。 * [possible to do] ZenzaWatch対応。 ローディング表示 置き換え完了時に何かリアクションを。 元の動画に戻すボタンで確認してから戻せるように。 ニコニコの時刻表示に時間単位追加 コメント投稿時の自動再生再開はオンオフ可能に。 [bug] Firefoxのblob処理が重いのかどうか? */ if(window === top && console.time) console.time(SCRIPTNAME); const SHORTSHIFT = 1;// Shift + 左右キーで移動する(秒) const CONTROLLER_HIDE = 4000;// コントローラを自動で隠すまでの時間 let site = { get: { originalVideo: () => $('#VideoPlayer video[src]'),//元の動画 controllerBoxContainer: () => $('.ControllerBoxContainer'),//コントローラー playerPlayButton: () => $('.PlayerPlayButton'),//再生 playerPauseButton: () => $('.PlayerPauseButton'),//停止 seekToHeadButton: () => $('.SeekToHeadButton'),//動画の先頭へ戻る playerSeekBackwardButton: () => $('.PlayerSeekBackwardButton'),//10秒戻る playerPlayTime: () => $('.PlayerPlayTime'),//時刻表示 playtime: () => $('.PlayerPlayTime-playtime'),//現在時刻 playerSeekForwardButton: () => $('.PlayerSeekForwardButton'),//10秒進む playerOptionButton: () => $('button[data-title="設定"]'),//設定 commentInputTextarea: () => $('.CommentInput-textarea'),//コメント入力欄 commentPostButton: () => $('.CommentPostButton'),//コメントする fixedFullscreen : () => $('#fixedFullscreen'),//コントローラーを常に表示する footerContainerLinks: () => $('.FooterContainer-links'),//動画ファイルアイコン提供元へのリンクを挿入するフッタ箇所 }, }; let originalVideo, replacedVideo, controller, ajustmentTime = 0, startTimer, hiddenTimer; let core = { initialize: function(){ core.addFileButton(); core.getOriginalVideo(); core.listenEvents(); core.addJumpButton(); core.addFooter(); core.addStyle(); }, addFileButton: function(){ let playerOptionButton = site.get.playerOptionButton(); if(!playerOptionButton) return setTimeout(core.addFileButton, 1000); let fileButton = createElement(core.html.fileButton()); let input = fileButton.querySelector('input[type="file"]'); fileButton.addEventListener('click', function(e){ input.click(); }); // ファイルを差し替えたときの処理 input.addEventListener('change', function(e){ log('changed!'); core.linkVideos(URL.createObjectURL(input.files[0])); core.addAjustmentInput(); }); playerOptionButton.parentNode.insertBefore(fileButton, playerOptionButton); }, addAjustmentInput: function(){ if($(`#${SCRIPTNAME}-ajustment`)) return; let playerPlayTime = site.get.playerPlayTime(); if(!playerPlayTime) return setTimeout(core.addAjustmentInput, 1000); let ajustment = createElement(core.html.ajustment()); let input = ajustment.querySelector('input'); // 調整値を変えたときの処理 input.addEventListener('change', function(e){ ajustmentTime = parseInt(input.value); core.syncVideos(); }); playerPlayTime.appendChild(ajustment); }, getOriginalVideo: function(){ originalVideo = site.get.originalVideo(); if(!originalVideo) return setTimeout(core.getOriginalVideo, 1000); core.observeOriginalVideo(); }, observeOriginalVideo: function(){ let observer = observe(originalVideo, function(records){ if(!replacedVideo) return; if(!records.some((r) => r.attributeName === 'src')) return; replacedVideo.parentNode.removeChild(replacedVideo); replacedVideo.classList.remove('loaded'); replacedVideo.src = ''; }, {attributes: true}); }, linkVideos: function(object){ // リプレイスビデオ要素の準備 replacedVideo = replacedVideo || createElement(core.html.replacedVideo()); replacedVideo.src = object; replacedVideo.classList.add('loaded'); originalVideo.parentNode.insertBefore(replacedVideo, originalVideo); // 連動 originalVideo.addEventListener('play', function(e){ log('originalVideo: play!'); core.syncVideos(); }); originalVideo.addEventListener('pause', function(e){ log('originalVideo: pause!'); core.syncVideos(); }); originalVideo.addEventListener('seeking', function(e){ log('originalVideo: seeking!'); core.syncVideos(); }); originalVideo.addEventListener('canplay', function(e){ log('originalVideo: canplay!'); core.syncVideos(); }); originalVideo.addEventListener('volumechange', function(e){ replacedVideo.volume = originalVideo.volume; }); // 連動(?) replacedVideo.addEventListener('seeking', function(e){ log('replacedVideo: seeking!'); }); replacedVideo.addEventListener('canplay', function(e){ log('replacedVideo: canplay!'); }); // オリジナルビデオの状態をコピー replacedVideo.currentTime = originalVideo.currentTime - ajustmentTime; replacedVideo.playbackRate = originalVideo.playbackRate; replacedVideo.volume = originalVideo.volume; // オリジナルビデオは影の存在となる originalVideo.style.visibility = 'hidden';//displayは上書きされる originalVideo.muted = true; }, syncVideos: function(){ let currentTime = originalVideo.currentTime - ajustmentTime; clearTimeout(startTimer); if(currentTime < 0){ replacedVideo.pause(); startTimer = setTimeout(function(){replacedVideo.play()}, - currentTime * 1000); }else{ originalVideo.paused ? replacedVideo.pause() : replacedVideo.play(); } replacedVideo.playbackRate = originalVideo.playbackRate; replacedVideo.currentTime = currentTime; }, listenEvents: function(){ // コントローラの初期状態は表示 controller = site.get.controllerBoxContainer(); controller.dataset.hidden = 'false'; let throttling; window.addEventListener('mousemove', function(e){ if(throttling) return; throttling = setTimeout(function(){throttling = 0}, 100); core.showController(); }, true); window.addEventListener('keydown', function(e){ core.showController(); let activeElement = document.activeElement, textExists = core.textExists(); switch(true){ // Shift以外の修飾キーが押されていれば無視する case(e.altKey || e.ctrlKey || e.metaKey): return; // 日本語入力変換中なら無視する case(e.isComposing): return; // 文字入力中ならデフォルトのカーソル移動を邪魔しない case(e.key === 'ArrowLeft' && textExists): return; case(e.key === 'ArrowRight' && textExists): return; // コマンドとコメント以外の入力欄では無視する case(['input', 'textarea'].includes(activeElement.localName) && !['CommentCommandInput', 'CommentInput-textarea'].some((c) => activeElement.classList.contains(c))): return; // Enter: 再生停止(フォーカスはコメント欄へ) case(e.key === 'Enter'): let textarea = site.get.commentInputTextarea(); // コメント投稿 if(activeElement === textarea && textExists){ site.get.commentPostButton().click(); if(originalVideo.paused) site.get.playerPlayButton().click();//停止中なら再生 } // コメント投稿でなければ停止もする else{ if(originalVideo.paused) site.get.playerPlayButton().click();//停止中なら再生 else site.get.playerPauseButton().click();//再生中なら停止 } textarea.focus(); break; // Shift+←: 1秒戻る case(e.key === 'ArrowLeft' && e.shiftKey): // 単純に減らすだけだとプレイヤの時刻が連動しない仕様のようなので、標準の10秒戻るを併用する。 let playtime = site.get.playtime(); site.get.playerSeekBackwardButton().click(); requestAnimationFrame(function(){ originalVideo.currentTime-= SHORTSHIFT; originalVideo.currentTime+= 10; }); activeElement.focus();//フォーカスを戻す break; // Shift+→: 1秒進む case(e.key === 'ArrowRight' && e.shiftKey): // 増加はふつうに連動してくれる。 originalVideo.currentTime+= SHORTSHIFT; break; // ←: 10秒戻る case(e.key === 'ArrowLeft'): site.get.playerSeekBackwardButton().click(); activeElement.focus();//フォーカスを戻す break; // →: 10秒進む case(e.key === 'ArrowRight'): site.get.playerSeekForwardButton().click(); activeElement.focus();//フォーカスを戻す break; default: return; } e.preventDefault(); e.stopPropagation(); core.syncVideos(); }, true); }, addJumpButton: function(){ let playtime = site.get.playtime(); if(!playtime) return setTimeout(core.addJumpButton, 1000); playtime.dataset.title = '指定時刻にジャンプ'; playtime.addEventListener('click', function(e){ let time = prompt('指定時刻にジャンプ:', playtime.textContent); if(time && time.match(/^[0-9:.]+$/)){ site.get.seekToHeadButton().click(); requestAnimationFrame(function(){ let t = time.split(':'), s = 1, m = 60*s, h = 60*m; switch(t.length){ case(3): return core.jumpTo(t[0]*h + t[1]*m + t[2]*s); case(2): return core.jumpTo(t[0]*m + t[1]*s); case(1): return core.jumpTo(t[0]*s); } }); } }, true); }, jumpTo: function(time){ originalVideo.currentTime = time; }, showController: function(){ clearTimeout(hiddenTimer); let fixedFullscreen = site.get.fixedFullscreen(); if(fixedFullscreen && fixedFullscreen.checked === true) return; controller.dataset.hidden = 'false'; hiddenTimer = setTimeout(function(){ if(core.textExists()) return;//文字入力中なら消さない controller.dataset.hidden = 'true'; }, CONTROLLER_HIDE); }, textExists: function(){ return document.activeElement.value && document.activeElement.value.length > 0; }, addFooter: function(){ let footerContainerLinks = site.get.footerContainerLinks(); if(!footerContainerLinks) return setTimeout(core.addFooter, 1000); footerContainerLinks.appendChild(createElement(core.html.footer())); }, addStyle: function(){ let style = createElement(core.html.style()); document.head.appendChild(style); }, html: { fileButton: () => ` `, ajustment: () => ` + `, replacedVideo: () => `