wildcard icon indicating copy to clipboard operation
wildcard copied to clipboard

Adapter autodetection?

Open karlicoss opened this issue 4 years ago • 0 comments

At the moment, the applicable pages are hardcoded in the adapter, so for example, the HN adapter can't handle the "show new" page and few other.

I'm sure it would improve when the adapters are separated from the extension, and there are user settings so they can modify the scope, etc., but I feel like there is a low hanging improvement possible now.

What if only the domain is specified (e.g. news.ycombinator.com), and the adapter tries to run regardless. If it succeeds, the toolbar is presented, and if it fails, we assume it doesn't work on the page. False positives feel very unlikely, the only danger is making the whole thing way too defensive, but to combat that, some kind of two-pass approach could be used. The first, 'check' step merely checks for the presence of the "table" on the page and signals if the adapter should be on. And the second, 'adapt' step does the same wildcard is doing now.

Using HN as an example:

  • check: document.querySelector("table.itemlist"). If it's null, the adapter is inactive, if it's non null, pass it to the next step.
  • adapt: does the same that scrapePage is doing now. Potentially could take in the DOM element extracted from check, to reuse the code

Alternative option is to keep everything in scrapePage, and up to the convention:

  • the first thing you do in scrapePage is check for the presence of the table. If it doesn't, you return a special object (or even null would do as long as it's distinguished from [] by typescript), otherwise you carry on.

karlicoss avatar May 08 '20 08:05 karlicoss