Skip to content

Commit 113447b

Browse files
committed
chore: dynamic content script
1 parent ecd58f6 commit 113447b

15 files changed

Lines changed: 411 additions & 395 deletions

webapp/_webapp/public/settings.html

Lines changed: 2 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -4,211 +4,10 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>PaperDebugger Settings</title>
7-
<style>
8-
* {
9-
margin: 0;
10-
padding: 0;
11-
box-sizing: border-box;
12-
}
13-
14-
body {
15-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
16-
background: #f5f5f5;
17-
color: #333;
18-
padding: 20px;
19-
min-height: 100vh;
20-
}
21-
22-
.container {
23-
max-width: 800px;
24-
margin: 0 auto;
25-
background: white;
26-
border-radius: 8px;
27-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
28-
padding: 30px;
29-
}
30-
31-
h1 {
32-
font-size: 24px;
33-
font-weight: 600;
34-
margin-bottom: 10px;
35-
color: #222;
36-
}
37-
38-
.subtitle {
39-
color: #666;
40-
font-size: 14px;
41-
margin-bottom: 30px;
42-
}
43-
44-
.section {
45-
margin-bottom: 30px;
46-
padding-bottom: 30px;
47-
border-bottom: 1px solid #eee;
48-
}
49-
50-
.section:last-child {
51-
border-bottom: none;
52-
margin-bottom: 0;
53-
padding-bottom: 0;
54-
}
55-
56-
.section-title {
57-
font-size: 18px;
58-
font-weight: 600;
59-
margin-bottom: 15px;
60-
color: #333;
61-
}
62-
63-
.section-description {
64-
color: #666;
65-
font-size: 14px;
66-
margin-bottom: 20px;
67-
line-height: 1.6;
68-
}
69-
70-
.permission-item {
71-
background: #f9f9f9;
72-
border: 1px solid #e0e0e0;
73-
border-radius: 6px;
74-
padding: 15px;
75-
margin-bottom: 15px;
76-
display: flex;
77-
justify-content: space-between;
78-
align-items: center;
79-
}
80-
81-
.permission-info {
82-
flex: 1;
83-
}
84-
85-
.permission-url {
86-
font-family: monospace;
87-
font-size: 13px;
88-
color: #3b82f6;
89-
margin-top: 5px;
90-
}
91-
92-
.permission-status {
93-
font-size: 12px;
94-
padding: 4px 8px;
95-
border-radius: 4px;
96-
margin-left: 15px;
97-
}
98-
99-
.permission-status.granted {
100-
background: #d1fae5;
101-
color: #065f46;
102-
}
103-
104-
.permission-status.not-granted {
105-
background: #fee2e2;
106-
color: #991b1b;
107-
}
108-
109-
button {
110-
background: #3b82f6;
111-
color: white;
112-
border: none;
113-
padding: 10px 20px;
114-
border-radius: 6px;
115-
font-size: 14px;
116-
font-weight: 500;
117-
cursor: pointer;
118-
transition: background 0.2s;
119-
}
120-
121-
button:hover {
122-
background: #2563eb;
123-
}
124-
125-
button:disabled {
126-
background: #9ca3af;
127-
cursor: not-allowed;
128-
}
129-
130-
.input-group {
131-
margin-bottom: 15px;
132-
}
133-
134-
label {
135-
display: block;
136-
font-size: 14px;
137-
font-weight: 500;
138-
margin-bottom: 8px;
139-
color: #333;
140-
}
141-
142-
input[type="text"] {
143-
width: 100%;
144-
padding: 10px;
145-
border: 1px solid #d1d5db;
146-
border-radius: 6px;
147-
font-size: 14px;
148-
font-family: monospace;
149-
}
150-
151-
input[type="text"]:focus {
152-
outline: none;
153-
border-color: #3b82f6;
154-
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
155-
}
156-
157-
.message {
158-
padding: 12px;
159-
border-radius: 6px;
160-
margin-top: 15px;
161-
font-size: 14px;
162-
}
163-
164-
.message.success {
165-
background: #d1fae5;
166-
color: #065f46;
167-
border: 1px solid #a7f3d0;
168-
}
169-
170-
.message.error {
171-
background: #fee2e2;
172-
color: #991b1b;
173-
border: 1px solid #fecaca;
174-
}
175-
176-
.message.info {
177-
background: #dbeafe;
178-
color: #1e40af;
179-
border: 1px solid #bfdbfe;
180-
}
181-
</style>
1827
</head>
1838
<body>
184-
<div class="container">
185-
<h1>PaperDebugger Settings</h1>
186-
<p class="subtitle">Manage extension permissions and settings</p>
187-
188-
<div class="section">
189-
<div class="section-title">Host Permissions</div>
190-
<div class="section-description">
191-
Request permissions to access specific websites. These permissions allow the extension to interact with the specified domains.
192-
</div>
193-
194-
<div class="input-group">
195-
<label for="permissionUrl">Website URL:</label>
196-
<input
197-
type="text"
198-
id="permissionUrl"
199-
placeholder="https://www.example.com/"
200-
value="https://www.google.com/"
201-
/>
202-
</div>
203-
204-
<button id="requestPermissionBtn">Request Permission</button>
205-
<div id="message"></div>
206-
207-
<div id="permissionsList" style="margin-top: 20px;"></div>
208-
</div>
209-
</div>
210-
211-
<script src="settings.js"></script>
9+
<div id="root"></div>
10+
<script type="module" src="settings.js"></script>
21211
</body>
21312
</html>
21413

webapp/_webapp/src/background.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { getAllCookies } from "./libs/browser";
1818
import { HANDLER_NAMES } from "./shared/constants";
1919
import { blobToBase64 } from "./libs/helpers";
20+
import { registerContentScripts } from "./libs/permissions";
2021

2122
export type Handler<A, T> = {
2223
name: string;
@@ -108,3 +109,5 @@ browserAPI.runtime?.onMessage?.addListener(
108109
return true;
109110
},
110111
);
112+
113+
registerContentScripts();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// can not running in content_script. registerContentScripts can only be called in service_worker.
2+
export async function registerContentScripts() {
3+
const origins = (await chrome.permissions.getAll()).origins || [];
4+
const scriptIds = (await chrome.scripting.getRegisteredContentScripts()).map(script => script.id);
5+
6+
console.log("[PaperDebugger] Unregistering dynamic content scripts", scriptIds);
7+
await chrome.scripting.unregisterContentScripts({ ids: scriptIds });
8+
9+
await chrome.scripting.registerContentScripts([{
10+
id: "content-script-main",
11+
js: ["paperdebugger.js"],
12+
persistAcrossSessions: true,
13+
matches: origins,
14+
world: "MAIN",
15+
}, {
16+
id: "content-script-intermediate",
17+
js: ["intermediate.js"],
18+
persistAcrossSessions: true,
19+
matches: origins,
20+
runAt: "document_start"
21+
}])
22+
23+
console.log("[PaperDebugger] Registration complete", origins);
24+
}

webapp/_webapp/src/main.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export const Main = () => {
156156
);
157157
};
158158

159+
console.log("[PaperDebugger] PaperDebugger injected, find toolbar-left or ide-redesign-toolbar-menu-bar to add button");
160+
159161
if (!import.meta.env.DEV) {
160162
onElementAppeared(".toolbar-left .toolbar-item, .ide-redesign-toolbar-menu-bar", () => {
161163
logInfo("initializing");

webapp/_webapp/src/manifest.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,15 @@
1212
},
1313
"host_permissions": ["*://*.overleaf.com/"],
1414
"optional_host_permissions": ["*://*/*"],
15-
"permissions": ["cookies", "storage"],
15+
"permissions": ["cookies", "storage", "scripting", "activeTab"],
1616
"options_page": "settings.html",
1717
"background": {
1818
"service_worker": "background.js"
1919
},
20-
"content_scripts": [
21-
{
22-
"js": ["paperdebugger.js"],
23-
"matches": ["https://*.overleaf.com/project/*"],
24-
"world": "MAIN"
25-
},
26-
{
27-
"js": ["intermediate.js"],
28-
"matches": ["https://*.overleaf.com/project/*"],
29-
"run_at": "document_start"
30-
}
31-
],
3220
"web_accessible_resources": [
3321
{
3422
"resources": ["images/*"],
35-
"matches": ["https://*.overleaf.com/*"]
23+
"matches": ["*://*/*"]
3624
}
3725
],
3826
"key": "[AUTO-GENERATED]"

0 commit comments

Comments
 (0)