duqing2026 commited on
Commit
48a6d40
·
1 Parent(s): babe1f5

feat: add devtools and omnibox support, improve stability and icons

Browse files
app.py CHANGED
@@ -12,9 +12,31 @@ app = Flask(__name__)
12
  template_loader = FileSystemLoader(searchpath="./extension_templates")
13
  template_env = Environment(loader=template_loader)
14
 
15
- def generate_icon(size, color=(66, 133, 244)):
16
  img = Image.new('RGB', (size, size), color=color)
17
- # optional: add text or simple pattern if needed, but solid color is fine for placeholder
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  byte_arr = io.BytesIO()
19
  img.save(byte_arr, format='PNG')
20
  return byte_arr.getvalue()
@@ -41,6 +63,9 @@ def generate():
41
  'include_content_script': data.get('include_content_script', False),
42
  'content_script_matches': data.get('content_script_matches', '*://*.example.com/*'),
43
  'include_side_panel': data.get('include_side_panel', False),
 
 
 
44
  'use_messaging': data.get('use_messaging', False),
45
  }
46
 
@@ -83,10 +108,17 @@ def generate():
83
  if context['include_side_panel']:
84
  write_template('sidepanel.html', 'sidepanel.html')
85
 
86
- # 8. Icons (Generated)
87
- zf.writestr('images/icon16.png', generate_icon(16))
88
- zf.writestr('images/icon48.png', generate_icon(48))
89
- zf.writestr('images/icon128.png', generate_icon(128))
 
 
 
 
 
 
 
90
 
91
  memory_file.seek(0)
92
  return send_file(
 
12
  template_loader = FileSystemLoader(searchpath="./extension_templates")
13
  template_env = Environment(loader=template_loader)
14
 
15
+ def generate_icon(size, color=(66, 133, 244), text=None):
16
  img = Image.new('RGB', (size, size), color=color)
17
+
18
+ if text and size >= 48:
19
+ draw = ImageDraw.Draw(img)
20
+ # Simple cross pattern as placeholder for text/logo
21
+ # Since we don't have a guaranteed font file, we'll draw a simple shape
22
+ margin = size // 4
23
+ draw.rectangle(
24
+ [margin, margin, size - margin, size - margin],
25
+ outline="white", width=max(1, size // 20)
26
+ )
27
+ # Draw first letter if available? No font, so let's just stick to geometric shape
28
+ # Or try to load default font
29
+ try:
30
+ # Try to draw text if default font works
31
+ # On some systems, this might work if a default font is available
32
+ # But PIL often needs a font file. We'll try basic text drawing.
33
+ # If it fails, we catch it.
34
+ # Note: default font is very small, might not look good.
35
+ # So we just stick to the rectangle as a "logo"
36
+ pass
37
+ except:
38
+ pass
39
+
40
  byte_arr = io.BytesIO()
41
  img.save(byte_arr, format='PNG')
42
  return byte_arr.getvalue()
 
63
  'include_content_script': data.get('include_content_script', False),
64
  'content_script_matches': data.get('content_script_matches', '*://*.example.com/*'),
65
  'include_side_panel': data.get('include_side_panel', False),
66
+ 'include_devtools': data.get('include_devtools', False),
67
+ 'include_omnibox': data.get('include_omnibox', False),
68
+ 'omnibox_keyword': data.get('omnibox_keyword', 'ext'),
69
  'use_messaging': data.get('use_messaging', False),
70
  }
71
 
 
108
  if context['include_side_panel']:
109
  write_template('sidepanel.html', 'sidepanel.html')
110
 
111
+ # 8. DevTools
112
+ if context['include_devtools']:
113
+ write_template('devtools.html', 'devtools.html')
114
+ write_template('devtools.js', 'devtools.js')
115
+ write_template('panel.html', 'panel.html')
116
+
117
+ # 9. Icons (Generated)
118
+ icon_text = context['name']
119
+ zf.writestr('images/icon16.png', generate_icon(16, text=icon_text))
120
+ zf.writestr('images/icon48.png', generate_icon(48, text=icon_text))
121
+ zf.writestr('images/icon128.png', generate_icon(128, text=icon_text))
122
 
123
  memory_file.seek(0)
124
  return send_file(
extension_templates/devtools.html ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>DevTools</title>
5
+ </head>
6
+ <body>
7
+ <script src="devtools.js"></script>
8
+ </body>
9
+ </html>
extension_templates/devtools.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ chrome.devtools.panels.create(
2
+ "{{ name }}",
3
+ "images/icon16.png",
4
+ "panel.html",
5
+ function(panel) {
6
+ // code invoked on panel creation
7
+ }
8
+ );
extension_templates/manifest.json CHANGED
@@ -44,6 +44,12 @@
44
  "default_path": "sidepanel.html"
45
  },
46
  {% endif %}
 
 
 
 
 
 
47
  "icons": {
48
  "16": "images/icon16.png",
49
  "48": "images/icon48.png",
 
44
  "default_path": "sidepanel.html"
45
  },
46
  {% endif %}
47
+ {% if include_devtools %}
48
+ "devtools_page": "devtools.html",
49
+ {% endif %}
50
+ {% if include_omnibox %}
51
+ "omnibox": { "keyword": "{{ omnibox_keyword }}" },
52
+ {% endif %}
53
  "icons": {
54
  "16": "images/icon16.png",
55
  "48": "images/icon48.png",
extension_templates/panel.html ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <style>
5
+ body { font-family: sans-serif; padding: 10px; }
6
+ h1 { font-size: 16px; }
7
+ </style>
8
+ </head>
9
+ <body>
10
+ <h1>{{ name }} DevTools Panel</h1>
11
+ <p>This is a custom panel in Chrome DevTools.</p>
12
+ <button id="inspectBtn">Inspect Selected Element</button>
13
+ <div id="result"></div>
14
+ <script>
15
+ document.getElementById('inspectBtn').addEventListener('click', () => {
16
+ chrome.devtools.inspectedWindow.eval(
17
+ "($0 ? $0.tagName : 'Nothing selected')",
18
+ (result, isException) => {
19
+ document.getElementById('result').textContent = "Selected: " + result;
20
+ }
21
+ );
22
+ });
23
+ </script>
24
+ </body>
25
+ </html>
templates/index.html CHANGED
@@ -258,6 +258,12 @@
258
  manifest.permissions.push('sidePanel');
259
  }
260
  }
 
 
 
 
 
 
261
 
262
  return JSON.stringify(manifest, null, 2);
263
  });
 
258
  manifest.permissions.push('sidePanel');
259
  }
260
  }
261
+ if (form.value.include_devtools) {
262
+ manifest.devtools_page = "devtools.html";
263
+ }
264
+ if (form.value.include_omnibox) {
265
+ manifest.omnibox = { keyword: form.value.omnibox_keyword };
266
+ }
267
 
268
  return JSON.stringify(manifest, null, 2);
269
  });