shot-scraper icon indicating copy to clipboard operation
shot-scraper copied to clipboard

Idea: JavaScript macros in the YAML file

Open simonw opened this issue 2 years ago • 3 comments

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 avatar Mar 13 '22 15:03 simonw

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

  • #9

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 avatar Mar 13 '22 15:03 simonw

Partly inspired by thinking about:

  • https://github.com/palewire/news-homepages/issues/4

simonw avatar Mar 13 '22 15:03 simonw

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

mheap avatar Apr 29 '23 13:04 mheap