Last active
May 13, 2022 00:49
-
-
Save fent/7763775 to your computer and use it in GitHub Desktop.
Scripts for controlling youtube videos. Now maintained at https://github.com/fent/dotfiles/tree/master/scripts
This file contains hidden or 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
# If in a playlist, play the next video. | |
tell application "Google Chrome" | |
repeat with t in tabs of windows | |
tell t | |
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then | |
execute javascript " | |
var player = | |
document.getElementById('movie_player') || | |
document.getElementsByTagName('embed')[0]; | |
var next = document.getElementsByClassName('yt-uix-button-icon-playlist-bar-next')[0]; | |
if (player && next) { | |
next.click(); | |
} | |
" | |
exit repeat | |
end if | |
end tell | |
end repeat | |
end tell |
This file contains hidden or 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
# Pause all youtube videos in all youtube tabs. | |
tell application "Google Chrome" | |
repeat with t in tabs of windows | |
tell t | |
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then | |
execute javascript " | |
var player = | |
document.getElementById('movie_player') || | |
document.getElementsByTagName('embed')[0]; | |
if (player) { | |
player.pauseVideo(); | |
} | |
" | |
end if | |
end tell | |
end repeat | |
end tell |
This file contains hidden or 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
# Play or pause a video. | |
tell application "Google Chrome" | |
repeat with t in tabs of windows | |
tell t | |
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then | |
execute javascript " | |
var player = | |
document.getElementById('movie_player') || | |
document.getElementsByTagName('embed')[0]; | |
if (player) { | |
if (player.getPlayerState() === 1) { | |
player.pauseVideo(); | |
} else { | |
player.playVideo(); | |
} | |
} | |
" | |
exit repeat | |
end if | |
end tell | |
end repeat | |
end tell |
This file contains hidden or 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
# If in a playlist and the current video time is <= 5 seconds, | |
# play the previous video, | |
# otherwise, rewind to the beginning of the current video and play. | |
tell application "Google Chrome" | |
repeat with t in tabs of windows | |
tell t | |
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then | |
execute javascript " | |
var player = | |
document.getElementById('movie_player') || | |
document.getElementsByTagName('embed')[0]; | |
if (player) { | |
var prev = document.getElementsByClassName('yt-uix-button-icon-playlist-bar-prev')[0]; | |
if (player.getCurrentTime() <= 5 && prev) { | |
prev.click(); | |
} else { | |
player.seekTo(0, true); | |
if (player.getPlayerState() !== 1) { | |
player.playVideo(); | |
} | |
} | |
} | |
" | |
exit repeat | |
end if | |
end tell | |
end repeat | |
end tell |
Can you make a script that set a timer to automatically pause on YouTube? On Firefox?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These will not work with the latest chrome version anymore. I have created some updated scripts to use with the new chrome version which can be found here https://gist.github.com/zachloubier/9b07fd21292a7dfb92d9.
I used these scripts as inspiration and just replaced the youtube api with vanilla js.