4
0

setup_firefox.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. """Prepare the Firefox-style suggestions screenshot."""
  3. import time
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. def _wait_for_body_attr(driver, attr, timeout=15):
  7. WebDriverWait(driver, timeout).until(
  8. lambda d: bool(d.find_element(By.TAG_NAME, "body").get_attribute(attr))
  9. )
  10. def _open_form(driver):
  11. _wait_for_body_attr(driver, "loaded-dashboard")
  12. action = driver.find_element(
  13. By.CSS_SELECTOR, '[title="Restart Docker Container"]'
  14. )
  15. action.click()
  16. _wait_for_body_attr(driver, "loaded-argument-form")
  17. driver.execute_script(
  18. """
  19. const form = document.getElementById('argument-popup');
  20. if (form) {
  21. form.style.margin = '2rem auto';
  22. form.style.maxWidth = '520px';
  23. }
  24. """
  25. )
  26. def run(driver):
  27. _open_form(driver)
  28. driver.execute_script(
  29. """
  30. const input = document.getElementById('container');
  31. input.focus();
  32. input.value = '';
  33. document.getElementById('doc-suggestions-overlay')?.remove();
  34. const rect = input.getBoundingClientRect();
  35. const menu = document.createElement('div');
  36. menu.id = 'doc-suggestions-overlay';
  37. menu.style.position = 'fixed';
  38. menu.style.left = `${rect.left}px`;
  39. menu.style.top = `${rect.bottom + 2}px`;
  40. menu.style.width = `${rect.width}px`;
  41. menu.style.background = '#fff';
  42. menu.style.border = '1px solid #ccc';
  43. menu.style.boxShadow = '0 1px 4px rgba(0, 0, 0, 0.15)';
  44. menu.style.font = '13px sans-serif';
  45. menu.style.zIndex = '9999';
  46. for (const label of [
  47. 'Firewall Controller',
  48. 'graefik',
  49. 'grafana',
  50. 'plex',
  51. 'WiFi Controller',
  52. ]) {
  53. const row = document.createElement('div');
  54. row.textContent = label;
  55. row.style.padding = '4px 8px';
  56. menu.appendChild(row);
  57. }
  58. document.body.appendChild(menu);
  59. """
  60. )
  61. time.sleep(0.2)