-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
222 lines (185 loc) · 7.84 KB
/
code.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
(async () => {
const api_url = 'https://api.penguinai.tech/v1/chat/completions';
async function fetchAndGetReqModels() {
try {
const response = await fetch(api_url.replace('/chat/completions', '/models'));
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.status} ${response.statusText}`);
}
const data = await response.json();
// Filter the models based on type "chat.completions"
return data.data
.filter(model => model.type === "chat.completions") // Only include "chat.completions" models
.map(model => ({ text: model.id, value: model.id })); // Map to desired structure
} catch (error) {
return [];
}
}
function createButton(text, bgColor, textColor, hoverColor) {
const button = document.createElement('button');
button.textContent = text;
Object.assign(button.style, {
marginTop: '10px',
padding: '5px 10px',
backgroundColor: bgColor,
color: textColor,
border: 'none',
cursor: 'pointer',
borderRadius: '6px',
transition: 'background-color 0.3s, transform 0.2s',
});
button.onmouseover = () => {
button.style.backgroundColor = hoverColor;
button.style.transform = 'scale(1.05)';
};
button.onmouseout = () => {
button.style.backgroundColor = bgColor;
button.style.transform = 'scale(1)';
};
return button;
}
function showModelSelectionModal(models) {
const modal = document.createElement('div');
Object.assign(modal.style, {
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
backgroundColor: 'white',
padding: '20px',
border: '1px solid black',
zIndex: '10000',
maxHeight: '80%',
overflowY: 'auto',
color: 'black',
borderRadius: '12px',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)',
});
const select = document.createElement('select');
select.style.width = '100%';
select.style.padding = '5px';
select.style.color = 'black';
select.style.backgroundColor = 'white';
select.style.border = '1px solid black';
models.forEach(model => {
const option = document.createElement('option');
option.value = model.value;
option.textContent = model.text;
select.appendChild(option);
});
const button = createButton('Select Model', '#4CAF50', 'white', '#45a049');
const heading = document.createElement('h2');
heading.textContent = 'Select a Model';
heading.style.color = 'black';
modal.appendChild(heading);
modal.appendChild(select);
modal.appendChild(document.createElement('br'));
modal.appendChild(button);
document.body.appendChild(modal);
return new Promise((resolve) => {
button.onclick = () => {
const selectedModel = select.value;
document.body.removeChild(modal);
resolve(selectedModel);
};
});
}
const models = await fetchAndGetReqModels();
if (models.length === 0) {
alert("No models available.");
return;
}
const selectedModel = await showModelSelectionModal(models);
if (!selectedModel) {
alert("No model selected.");
return;
}
const content = document.body.innerText || document.body.textContent;
function showInputModal() {
const modal = document.createElement('div');
Object.assign(modal.style, {
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
backgroundColor: 'white',
padding: '20px',
border: '1px solid black',
zIndex: '10000',
borderRadius: '12px',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)',
});
const input = document.createElement('textarea');
input.placeholder = 'Add any additional comments or context (optional)';
input.style.width = '100%';
input.style.height = '100px';
input.style.marginBottom = '10px';
const button = createButton('Submit', '#4CAF50', 'white', '#45a049');
modal.appendChild(input);
modal.appendChild(document.createElement('br'));
modal.appendChild(button);
document.body.appendChild(modal);
return new Promise((resolve) => {
button.onclick = () => {
const additionalComments = input.value.trim();
document.body.removeChild(modal);
resolve(additionalComments);
};
});
}
const additionalComments = await showInputModal();
let messages = [{ role: "user", content }];
if (additionalComments) {
messages.push({ role: "user", content: additionalComments });
}
try {
const response = await fetch(api_url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://gptcall.net/',
'Referer': 'https://gptcall.net/'
},
body: JSON.stringify({
model: selectedModel,
messages: [
{ role: "user", content: "You are a browser console code that analyzes a webpage and provides answers. You have no memory, and you must respond in the language of the webpage or the language of the user's input. If the user asks a question in a specific language or if the webpage is in a certain language, respond in that language, not in English by default. Your developer is Justablock. Here is the webpage content and the user's message for your analysis: If sending *text*, it won't show 'fat', and neither `code` nor anything else like that will work." },
...messages
]
}),
});
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.status} ${response.statusText}`);
}
const data = await response.json();
const botResponse = data.choices[0].message.content;
const resultModal = document.createElement('div');
Object.assign(resultModal.style, {
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
backgroundColor: 'white',
padding: '20px',
border: '1px solid black',
zIndex: '10000',
maxHeight: '80%',
overflowY: 'auto',
color: 'black',
borderRadius: '12px',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)',
});
const responseHeading = document.createElement('h2');
responseHeading.textContent = "AI Analysis And Answer:";
const responseParagraph = document.createElement('p');
responseParagraph.textContent = botResponse;
const closeButton = createButton("Close", '#f44336', 'white', '#e53935');
resultModal.appendChild(responseHeading);
resultModal.appendChild(responseParagraph);
resultModal.appendChild(closeButton);
document.body.appendChild(resultModal);
closeButton.onclick = () => document.body.removeChild(resultModal);
} catch (error) {
alert("Error sending prompt to AI: " + error.message);
}
})();