A software tool called runScriptFromWebPage allows for effortless execution of selected shell and Apple scripts from the top web page.
Testing has shown that runScriptFromWebPage works exceptionally well with the Safari browser. However, if you're using a different browser, you can change $webBrowser to the name of your preferred browser. As long as that browser supports the 'do JavaScript' command in AppleScript, you should still be able to use this software without any issues.
It's important to note that runScriptFromWebPage uses JavaScript to get the selected text. As a result, it only works with HTML pages (not with plain text pages). Overall, if you're someone who frequently uses scripts on web pages, then runScriptFromWebPage is definitely worth checking out.