4 ms·
For those using firefox there is tridactyl available as others have commented as well. They've gone a step further introducing native messaging [1][2] which ope
by kytazo 4y ago
For those using firefox there is tridactyl available as others have commented as well. They've gone a step further introducing native messaging [1][2] which opens up an endless ways of interacting with the underlying OS which makes implementing all sorts of useful day-to-day functionality such as personal automation a joyful breeze.
For example, saving the current page in a local file can be as easy as:
tri.excmds.exclaim_quiet ('echo "' + document.location.href + '"' > $HOME/notes')
Sky is the limit given that you can interface with any page with JS and then pipe and process the output with any system utility or system context.
A simple example for demonstration would be copying the contents of the body tag, piping them to a readability[3] util and have the output saved to a local vault.
Or have a video played with mpv with a press of a button since you can invoke any of these functions be it custom or built-in targeting any element the same way you would follow a link by hinting.
Here are a few other, pretty interesting use cases as seen in examplar custom user configurations taken from their github wiki[4]
alias playAllVideos js tri.native.run("mpv --really-quiet --ontop --keepaspect-window --profile=protocol.http " + Array.from(document.querySelectorAll("a, iframe, video")).reduce((s, e) => {let r=(/^https?:\/\/((www.)?youtu((\.be\/)|(be\.com\/((embed\/)|(watch\?v=))))[^ ]+)|(.+\.webm)$/);let l="";if(e.tagName=="IFRAME")l=e.src.match(r);else if(e.tagName=="A")l=e.href.match(r)||e.innerText.match(r);else if(e.tagName=="VIDEO")l=[e.currentSrc?e.currentSrc:e.src];console.log(l);return s+(l && l.length > 0 && s.indexOf(l[0])<0?"'"+l[0]+"' ":"")},""))
alias gitclone jsb -p tri.native.run("git clone --depth=1 '" + JS_ARG + "' /home/me/prog/" + JS_ARG.split("/").slice(-1))
alias rsssave jsb -p tri.native.run('cat >> ~/.config/newsboat/urls', JS_ARG + "\n")
alias openGithubNotifications composite js Array.from(document.querySelectorAll("li.list-group-item > span:nth-child(1) > a:nth-child(2)")).map(e => e.href) | jsb -p JS_ARG.forEach(url => tri.excmds.tabopen(url))
Edit: I assume native messaging has security implications you should probably consider if the browser is running directly with your system without any means of isolation like sandboxing with bubblewrap or better running under a virtual environment.
[1] https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Web...
[2] https://github.com/tridactyl/native_messenger https://github.com/tridactyl/native_messenger
[3] https://github.com/cixtor/readability https://github.com/cixtor/readability
[4] https://github.com/tridactyl/tridactyl/wiki/ https://github.com/tridactyl/tridactyl/wiki/
- bovine3dom 4y agoIf you're sending untrusted strings to the native messenger, it would be best to escape them with shellescape - https://github.com/tridactyl/tridactyl/blob/f2479c64761358c62aa6da82df0e4f4d77d528e2/src/excmds.ts#L3804 https://github.com/tridactyl/tridactyl/blob/f2479c64761358c6... Otherwise a malicious website targeting Tridactyl users who use the native messenger could gain shell access when you triggered your command on them.
- noname120 4y agoFantastic! Thank you for expanding on your use case.