LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Shell script for browser extensions? (https://www.linuxquestions.org/questions/linux-desktop-74/shell-script-for-browser-extensions-4175706131/)

Turbocapitalist 01-09-2022 11:42 PM

Shell script for browser extensions?
 
I have a one-liner shell script I'd like to apply from time to time to various web pages with the least amount of effort. It uses xmlstarlet but I could easily convert it to XSLT instead.

How would it be possible to turn that into a plug-in or extension for Firefox or Chromium? Must javascript always be involved or can I use plain shell scripting instead? There is a lot of material out there but what I have found so far is many years out of date.

pan64 01-10-2022 12:47 AM

do you want to preprocess the page before displaying it or do you want to collect and save locally some info based on an url?

Turbocapitalist 01-10-2022 01:04 AM

Either is fine, whatever is the least work to run an XPath over the document before I get around to reading it.

boughtonp 01-10-2022 08:02 AM


 
I tried to do something similar last year, but I don't think it's possible to escape the JavaScript sandbox via Extension, and it wasn't worth the effort to pursue figuring out if/how Plugins could do it - but if you do figure it out I'd be interested to know.


Guttorm 01-10-2022 12:00 PM

For browser extensions, Javascript is the only option. Actually there's also WASM, but compiling a shell script to WASM? It's maybe possible - but very complicated, and you will still need Javascript for the actual extensions. Also, WASM cannot access files, links or anything - it's sandboxed for a reason.

Every browser (and Javascript) has a good XML parser with xpath support. So it shouldn't be very hard to port it.

https://developer.mozilla.org/en-US/..._in_JavaScript

I would start with a super simple example extension from here:

https://developer.mozilla.org/en-US/...sions/Examples

For example borderify. Then do some xpath magic - either with the DOM or an external xml source. It can be done with very few lines of code. And if you get stuck, post the code in the programming forum.

Good luck.

Turbocapitalist 01-11-2022 03:15 AM

Thanks. The link about XPath in javascript will be very useful once I brush up on the language.

However, the borderify script injects javascript into the page. For various reasons outside my influence, I cannot turn on javascript for the specific site to be processed. Maybe there is another example which adjusts the HTML itself without injecting javascript?

lvm_ 01-11-2022 03:34 AM

Check Greasemonkey https://addons.mozilla.org/en-US/fir.../greasemonkey/

ondoho 01-12-2022 01:46 AM

The "Open With..." addon allows you to run any executable against any link/page.


All times are GMT -5. The time now is 09:19 PM.