dan...@dantleech.com <dan...@dantleech.com> wrote: > Hi all, > > Is there a way that I could automatically execute a javascript file > when > a certain content type is loaded? > > For example, when the response from the server is application/json then > execute > a script (e.g. `VIMB_CONFIG_DIR/scripts/format_json.js`) that will > pretty print the JSON document.
At the time there is no direct was to do such things based on the documents mime type. > Or is there another way to achieve a similar effect? I can't imagine how this could be achieved. Even if you set up :autocmd for LoadFinished you don't have the mime type available. But hey, you can try something like this. Add autocmd to check the content of each loaded page :autocmd LoadFinished * sh! ~/bin/runJsonPrettifier Script that is feed with the page content to check if it's JSON (runJsonPrettifier). #!/usr/bin/env bash cmd="<Esc>::e document.getElementsByTagName('body')[0].innerHTML<CR>" content=$(echo "$cmd" | socat - UNIX-CONNECT:$VIMB_SOCKET) if [[ "$content" = isJASON ]]; then echo "<Esc>:e prettyPrintJSON($content);<CR>" | socat - UNIX-CONNECT:$VIMB_SOCKET fi I'm not sure if this works. But it's a really overkill and not the direct way. But maybe this is an inspiration to get your JSON pretty. Daniel ------------------------------------------------------------------------------ New Year. New Location. New Benefits. New Data Center in Ashburn, VA. GigeNET is offering a free month of service with a new server in Ashburn. Choose from 2 high performing configs, both with 100TB of bandwidth. Higher redundancy.Lower latency.Increased capacity.Completely compliant. http://p.sf.net/sfu/gigenet _______________________________________________ vimb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vimb-users