アプリの学習を、ブラウザでYoutubeのチュートリアル動画を見ながら進めたい場合、いちいちウィンドウを切り替えるのが面倒だ。
そこで、アプリのウィンドウにいながらにして動画を一時停止、再生、巻き戻し、早送りができたら便利になるよね。
Mac環境での構築方法となるが、メモしておく。
環境は「Mac + (BraveBrowser)Chrome + Stream Deck」となります。
Brave Browser(Chrome)の設定をする
メニューバーから、
表示 → 開発/管理 → Apple Events からの JavaScript を許可
をONにする。
AppleScript経由でタブ内のJavaScriptを実行できるが、この許可はデフォルトで無効になっている。
Stream Deckを設定
Stream Deckにプラグイン「Mac Script Runner(by Schwab Music)」をインストールして下記のスクリプトをそれぞれ設定していく。
10秒巻き戻し
tell application "Brave Browser"
tell active tab of window 1
execute javascript "var v=document.querySelector('video'); if(v){v.currentTime=Math.max(0,v.currentTime-10);}"
end tell
end tell再生/一時停止
tell application "Brave Browser"
tell active tab of window 1
execute javascript "var v=document.querySelector('video'); if(v){v.paused?v.play():v.pause();}"
end tell
end tell10秒早送り
tell application "Brave Browser"
tell active tab of window 1
execute javascript "var v=document.querySelector('video'); if(v){v.currentTime=Math.min(v.duration,v.currentTime+10);}"
end tell
end tell1コマ戻し
30fpsを想定し、1/30秒 戻す。
tell application "Brave Browser"
tell active tab of window 1
execute javascript "var v=document.querySelector('video'); if(v){v.pause();v.currentTime=Math.max(0,v.currentTime-(1/30));}"
end tell
end tell1コマ送り
30fpsを想定し、1/30秒 進める。
tell application "Brave Browser"
tell active tab of window 1
execute javascript "var v=document.querySelector('video'); if(v){v.pause();v.currentTime=Math.min(v.duration,v.currentTime+(1/30));}"
end tell
end tell字幕 ON/OFF
YouTubeプレイヤーの字幕ボタンをJavaScriptからクリックする。
tell application "Brave Browser"
tell active tab of window 1
execute javascript "var b=document.querySelector('.ytp-subtitles-button'); if(b){b.click();}"
end tell
end tell