Skip to content

Instantly share code, notes, and snippets.

@whobutsb
Created October 19, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whobutsb/a0785d47dbe9578c4557d08c9916f391 to your computer and use it in GitHub Desktop.
Save whobutsb/a0785d47dbe9578c4557d08c9916f391 to your computer and use it in GitHub Desktop.
Play and Pause YouTube from JXA
var chrome = Application("Google Chrome");
var windows = chrome.windows;
for(i = 0; i < windows.length; i++){
var tabs = windows[i].tabs;
for(j = 0; j < tabs.length; j++){
var url = tabs[j].url();
if(url.match(/youtube.com/)){
tabs[j].execute({ javascript: "document.querySelector('.ytp-play-button').click();" });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment