Hacking around with JavaScript and Shortcuts in iOS 12
Let’s ramp it up a little more, and try to implement a shortcut that activates gyroscope scrolling on any webpage. If your phone is tilted back, it’ll scroll up, start bringing it upright, we’ll scroll down, and bring it up to 90 degrees, and we’ll scroll down even faster.
Don’t want to wait? I’ve already built and uploaded this Shortcut to GitHub, so you can download and use it straight away:
Follow the same procedure as before to create a new Shortcut, but paste in the above JavaScript code. This code is a little more complex, but nothing we shouldn’t be able to follow:
- Create a function that handles device orientation change
- Inside that function, grab the “beta” direction (horizontal tilt) and check the value
- Based on the value, do nothing, scroll up, scroll down, or scroll down faster
- Assign our function to the
deviceorientation
event - Call the
completion()
handler to tell Shortcuts we’re done
This is pretty crude, but will do the trick for now. Make sure you set up the share sheet and Safari Web Page triggers in the Shortcut configuration, save it, and give it a whirl. You should be able to tilt your phone back and forth, and scroll up and down the page!
So this is pretty cool, we can interact with the page, get device details, and make it do stuff!