From anonymous, 1 Month ago, written in Python.
Embed
  1. import typing
  2.  
  3. from qutebrowser.api import cmdutils, apitypes, hook, message
  4.  
  5.  
  6. @cmdutils.register()
  7. @cmdutils.argument('tab', value=cmdutils.Value.cur_tab)
  8. def has_leaflet(tab: apitypes.Tab) -> None:
  9.     """Check whether a website uses leaflet."""
  10.     tab.elements.find_css('.leaflet-container', callback=show_osm_message,
  11.                           error_cb=show_error_message)
  12.  
  13.  
  14. def show_error_message(error: str) -> None:
  15.     message.error(str(error))
  16.  
  17.  
  18. def show_osm_message(elements: typing.List[apitypes.WebElement]) -> None:
  19.     if elements:
  20.         message.info("Yay, this site uses Leaflet!")
  21.     else:
  22.         message.info("This site does not use Leaflet...")
  23.  
  24. @hook.init()
  25. def init(_context: apitypes.InitContext) -> None:
  26.     message.info("osmtest initialized")
  27.