You have to select each message one by one. It takes about 4 "clicks" to successfully delete a message.
Once you initiate the script, it will run every second. If a message has the ability to be deleted, it will be. If not, it will be archived. Some "InMail" messages cannot be deleted on the web app. This script should work as long as LI doesn't change their page layout or element names, which will happen eventually.
Last tested: April, 24, 2019