Created
January 30, 2020 14:41
-
-
Save mvaneijgen/3c44c733f2a462dae7ca372f1884f8b3 to your computer and use it in GitHub Desktop.
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
to clickClassName2(theClassName, elementnum) | |
if application "Safari" is running then | |
try | |
tell application "Safari" | |
repeat with t in tabs of windows | |
if URL of t contains "youtube.com/watch" then | |
tell t | |
do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" | |
end tell | |
end if | |
end repeat | |
end tell | |
end try | |
else | |
return "" | |
end if | |
end clickClassName2 | |
clickClassName2("ytp-play-button ytp-button", 0) |
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
set str to "" as string | |
if ((str is equal to str) and (application "Safari" is running)) then | |
tell application "Safari" | |
repeat with t in tabs of windows | |
tell t | |
if URL starts with "https://www.youtube.com/watch" then | |
set state to do JavaScript [¬ | |
"document", ¬ | |
".querySelectorAll('div[class*=\"-mode\"]')[0]", ¬ | |
".className", ¬ | |
".match(/(playing|paused|ended)-mode/)[1]"] ¬ | |
as text | |
if state = "playing" then | |
set vidName to (do JavaScript " document.getElementsByTagName('title')[0].innerHTML" as text) | |
return text 1 thru -11 of vidName | |
else if state = "paused" then | |
return "(Paused)" | |
else if state = "ended" then | |
return "(Video Ended)" | |
end if | |
end if | |
end tell | |
end repeat | |
end tell | |
else | |
return "" | |
end if | |
return str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment