Created
October 19, 2018 15:29
-
-
Save whobutsb/45717993373a5ecafd64cd91c5fcf384 to your computer and use it in GitHub Desktop.
Play and Pause SoundCloud with JXA
This file contains 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
// grab the chrome object | |
var chrome = Application("Google Chrome"); | |
// grab all of the chrome windows | |
var windows = chrome.windows; | |
// loop through the chrome windows | |
for(i = 0; i < windows.length; i++){ | |
// grab all of the tabs for the window | |
var tabs = windows[i].tabs; | |
// loop through the tabs | |
for(j = 0; j < tabs.length; j++){ | |
// grab the url for the tab | |
var url = tabs[j].url(); | |
// check to see if the tab url matches "soundcloud.com" | |
if(url.match(/soundcloud.com/)){ | |
// in the tab lets execute some javascript | |
tabs[j].execute({ | |
// select the .playControl div and click it! | |
javascript: "document.querySelector('.playControl').click();" | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment