Created
April 8, 2013 21:54
-
-
Save echosa/5340883 to your computer and use it in GitHub Desktop.
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
on findTurntableTab() | |
set AppleScript's text item delimiters to "/" | |
set foundTab to "no" | |
tell application "Google Chrome" | |
set theWindows to get every window | |
repeat with theWindow in theWindows | |
repeat with theTab in every tab in theWindow | |
set theURL to URL of theTab | |
set baseURL to text item 3 of theURL | |
if baseURL = "turntable.fm" then | |
tell theTab | |
if execute javascript " | |
function isValidTab() { | |
var ret = true; | |
for (i in document.getElementsByClassName('alert-message')) { | |
var e = document.getElementsByClassName('alert-message')[i]; | |
if (e.innerHTML == 'This session has been disconnected because you signed on from another location. Refresh this page if you want to continue.') { | |
ret = false; | |
} | |
} | |
return ret; | |
} | |
isValidTab();" then | |
set foundTab to theTab | |
end if | |
end tell | |
end if | |
end repeat | |
end repeat | |
end tell | |
return foundTab | |
end findTurntableTab | |
on runTTfunc(theTab) | |
tell application "Google Chrome" | |
tell theTab | |
set AppleScript's text item delimiters to " " | |
set cmd to text item 1 of "{query}" | |
try | |
set param to text item 2 of "{query}" | |
on error | |
set param to "" | |
end try | |
if "{query}" = "up" or "{query}" = "down" then | |
execute javascript "ttp.vote('{query}');" | |
return "Song {query} voted." | |
else if "{query}" = "add" then | |
execute javascript "ttp.vote('up');" | |
execute javascript "ttp.roommanager.$queueAdd.click();" | |
return "Song {query} voted and added to playlist." | |
else if cmd = "pl" then | |
if execute javascript " | |
function mySwitchPlaylist() { | |
var ret = false; | |
document.getElementById('playlist-display').click(); | |
for (i in document.getElementsByClassName('playlist-label')) { | |
var e = document.getElementsByClassName('playlist-label')[i]; | |
if (e.innerHTML == '" & param & "') { | |
e.click(); | |
ret = true; | |
} | |
}; | |
if (ret == false) { | |
document.getElementById('playlist-display').click(); | |
} | |
return ret; | |
} | |
mySwitchPlaylist();" then | |
return "Playlist " & param & " selected." | |
else | |
return "Couldn't select playlist " & param & "." | |
end if | |
else | |
return "Command " & cmd & " not run." | |
end if | |
end tell | |
end tell | |
end runTTfunc | |
set myTab to findTurntableTab() | |
if myTab is not "no" then | |
runTTfunc(myTab) | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment