-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcontent.js
113 lines (103 loc) · 3.35 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function showBanner(message, isError = false) {
/* Remove existing banner if any */
const existingBanner = document.getElementById('url2md-banner');
if (existingBanner) {
existingBanner.remove();
}
/* Create new banner */
const banner = document.createElement('div');
banner.id = 'url2md-banner';
banner.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 15px 20px;
border-radius: 5px;
background-color: ${isError ? '#ff4444' : '#44bb44'};
color: white;
z-index: 10000;
font-family: Arial, sans-serif;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
transition: opacity 0.5s ease-in-out;
`;
banner.textContent = message;
document.body.appendChild(banner);
/* Remove banner after 3 seconds */
setTimeout(() => {
banner.style.opacity = '0';
setTimeout(() => banner.remove(), 500);
}, 3000);
}
function showPermissionDialog() {
/* Remove any existing dialog */
const existingDialog = document.getElementById('url2md-dialog');
if (existingDialog) {
existingDialog.remove();
}
/* Create dialog */
const dialog = document.createElement('div');
dialog.id = 'url2md-dialog';
dialog.style.cssText = `
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
z-index: 10001;
font-family: Arial, sans-serif;
max-width: 400px;
text-align: center;
`;
const message = document.createElement('p');
message.textContent = 'This extension needs permission to access web2md.answer.ai to convert pages to markdown. Would you like to grant this permission?';
message.style.marginBottom = '20px';
const buttonContainer = document.createElement('div');
buttonContainer.style.display = 'flex';
buttonContainer.style.justifyContent = 'center';
buttonContainer.style.gap = '10px';
const allowButton = document.createElement('button');
allowButton.textContent = 'Allow';
allowButton.style.cssText = `
padding: 8px 16px;
background: #44bb44;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
`;
allowButton.onclick = () => {
chrome.runtime.sendMessage({ type: 'USER_GRANTED_PERMISSION' });
dialog.remove();
};
const denyButton = document.createElement('button');
denyButton.textContent = 'Deny';
denyButton.style.cssText = `
padding: 8px 16px;
background: #ff4444;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
`;
denyButton.onclick = () => {
showBanner('Permission denied', true);
dialog.remove();
};
buttonContainer.appendChild(allowButton);
buttonContainer.appendChild(denyButton);
dialog.appendChild(message);
dialog.appendChild(buttonContainer);
document.body.appendChild(dialog);
}
/* Listen for messages from background script */
chrome.runtime.onMessage.addListener((message) => {
if (message.type === 'REQUEST_PERMISSION') {
showPermissionDialog();
} else {
showBanner(message.text, message.isError);
}
return false;
});