Permalink
Browse files

add song notification and volume control

  • Loading branch information...
1 parent 4aa487f commit 91fff291c3f53322bc887c317840c3fb0934b901 @atsuya committed Dec 15, 2012
Showing with 46 additions and 5 deletions.
  1. +3 −0 chrome/current-song.scpt
  2. +37 −5 chrome/lib/controller.scpt
  3. +3 −0 chrome/volume-down.scpt
  4. +3 −0 chrome/volume-up.scpt
View
@@ -0,0 +1,3 @@
+set Controller to run script ("script s" & return & (read alias (POSIX file "./chrome/lib/controller.scpt") as «class utf8») & return & "end script " & return & "return s")
+
+Controller's notifyCurrentSong()
View
@@ -8,9 +8,31 @@ on control(keyCode)
document.dispatchEvent(event);
"
- tell application "Google Chrome"
- set targetTab to null
+ set targetTab to activeTab() of me
+ executeJavaScript(targetTab, code) of me
+end control
+
+on notifyCurrentSong()
+ set targetTab to activeTab() of me
+
+ set songCode to "document.querySelector('.playerSongTitle .fade-out-content').innerHTML"
+ set song to executeJavaScript(targetTab, songCode) of me
+
+ set artistCode to "document.querySelector('.playerArtist .fade-out-content').innerHTML"
+ set artist to executeJavaScript(targetTab, artistCode) of me
+
+ notify(song, artist) of me
+end notifyCurrentSong
+
+on notify(name, message)
+ set command to "/usr/local/bin/growlnotify -n " & quoted form of name & " -m " & quoted form of message
+ do shell script command
+end notify
+
+on activeTab()
+ set targetTab to null
+ tell application "Google Chrome"
repeat with theWindow in every window
repeat with theTab in every tab of theWindow
if theTab's title ends with "- Google Play" then
@@ -19,7 +41,17 @@ on control(keyCode)
end if
end repeat
end repeat
-
- execute targetTab javascript code
end tell
-end control
+
+ return targetTab
+end activeTab
+
+on executeJavaScript(activeTab, code)
+ set result to null
+
+ tell application "Google Chrome"
+ set result to execute activeTab javascript code
+ end tell
+
+ return result
+end executeJavaScript
View
@@ -0,0 +1,3 @@
+set Controller to run script ("script s" & return & (read alias (POSIX file "./chrome/lib/controller.scpt") as «class utf8») & return & "end script " & return & "return s")
+
+Controller's control(189)
View
@@ -0,0 +1,3 @@
+set Controller to run script ("script s" & return & (read alias (POSIX file "./chrome/lib/controller.scpt") as «class utf8») & return & "end script " & return & "return s")
+
+Controller's control(187)

0 comments on commit 91fff29

Please sign in to comment.