Skip to content

Instantly share code, notes, and snippets.

@nonchip
Last active August 29, 2015 14:03
Show Gist options
  • Save nonchip/6a5d38cf29e8cd611006 to your computer and use it in GitHub Desktop.
Save nonchip/6a5d38cf29e8cd611006 to your computer and use it in GitHub Desktop.
Chrome remote JS using DevTools-JSON-server
#!/bin/zsh
JSON_URL="http://127.0.0.1:9234/json"
FIND_URL="$1"
SOCK_URL="$(curl -s "$JSON_URL" | grep -A 1 '"url":.*'"$FIND_URL" | tail -n 1 | cut -d'"' -f 4)"
JS_COMMAND="$(cat)"
REQUEST='{"id":1,"method":"Runtime.evaluate","params":{"expression":"'"$JS_COMMAND"'","objectGroup":"console","includeCommandLineAPI":true,"returnByValue":false}}'
echo -n "$REQUEST" | wssh -m text -n -q 0$2 "$SOCK_URL"
#!/bin/zsh
google-chrome --remote-debugging-port=9234 "$@"
#!/bin/zsh
if [ "$1" = "pause" ]
then ./chromeRemote.sh https://www.youtube.com/watch <<-END
\$(\".ytp-button-pause\").click();
END
fi
if [ "$1" = "play" ]
then ./chromeRemote.sh https://www.youtube.com/watch <<-END
\$(\".ytp-button-play\").click();
END
fi
if [ "$1" = "toggle" ]
then ./chromeRemote.sh https://www.youtube.com/watch <<-END
\$(\".html5-player-chrome .ytp-button:first-child\").click();
END
fi
if [ "$1" = "prev" ]
then ./chromeRemote.sh https://www.youtube.com/watch <<-END
\$(\".prev-playlist-list-item\").click();
END
fi
if [ "$1" = "next" ]
then ./chromeRemote.sh https://www.youtube.com/watch <<-END
\$(\".next-playlist-list-item\").click();
END
fi
if [ "$1" = "related" ]
then R=$((($RANDOM%3)+2))
./chromeRemote.sh https://www.youtube.com/watch <<-END
\$(\"#watch-related .related-list-item:nth-child($R) .related-video\").click();
END
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment