setup_chrome.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env python3
  2. """Prepare the Chrome-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 #888';
  43. menu.style.boxShadow = '0 2px 6px rgba(0, 0, 0, 0.2)';
  44. menu.style.font = '13px sans-serif';
  45. menu.style.zIndex = '9999';
  46. const items = [
  47. ['firewall-controller', 'Firewall Controller'],
  48. ['graefik', ''],
  49. ['grafana', ''],
  50. ['plex', ''],
  51. ['wifi-controller', 'WiFi Controller'],
  52. ];
  53. for (const [value, label] of items) {
  54. const row = document.createElement('div');
  55. row.style.padding = '4px 8px';
  56. row.style.lineHeight = '1.3';
  57. const valueEl = document.createElement('div');
  58. valueEl.textContent = value;
  59. valueEl.style.fontWeight = label ? '600' : '400';
  60. row.appendChild(valueEl);
  61. if (label) {
  62. const labelEl = document.createElement('div');
  63. labelEl.textContent = label;
  64. labelEl.style.color = '#666';
  65. labelEl.style.fontSize = '12px';
  66. row.appendChild(labelEl);
  67. }
  68. menu.appendChild(row);
  69. }
  70. document.body.appendChild(menu);
  71. """
  72. )
  73. time.sleep(0.2)