simonw / shot-scraper

A command-line utility for taking automated screenshots of websites
https://shot-scraper.datasette.io
Apache License 2.0
1.67k stars 74 forks source link

Idea: JavaScript macros in the YAML file #36

Open simonw opened 2 years ago

simonw commented 2 years ago

This is just a harebrained idea at the moment: what if the YAML could define JavaScript that could be applied to all of the shots in the file, with customizations for each shot?

Something like this:

macros:
- javascript: |
    Array.from(
      document.querySelectorAll(
        ShotScraper.inputs.toRemove
      )
    ).forEach(el => el.style.display='none')
shots:
- url: https://site-one.com/
  output: one.png
  inputs:
    toRemove: "#ad,#footer"
- url: https://site-two.com/
  output: two.png
  inputs:
    toRemove: "#adbanner"
simonw commented 2 years ago

This could even be extended as a way to support annotations:

Named macros could be defined in a separate file and then that file name passed to the multi command as an option.

shot-scraper multi shots.yaml --macro macros.yaml 
simonw commented 2 years ago

Partly inspired by thinking about:

mheap commented 1 year ago

We're starting to build out our usage of shot-scraper and could really use the ability to define macros for usage later. Not so much the inputs functionality, just predefined functions would be enough.

My Python is rusty, but I'd be happy to try and PR this without inputs if you're receptive