-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
69 lines (64 loc) · 2.49 KB
/
popup.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
document.getElementById("saveSettings").addEventListener("click", () => {
let url = document.getElementById("urlInput").value;
let numberOfTweets = document.getElementById("numberOfTweets").value;
let llmApiKey = document.getElementById("llmApiKey").value || "LOCAL-API";
if (url && numberOfTweets) {
chrome.storage.local.set(
{
tweetPostUrl: url,
numberOfTweets: parseInt(numberOfTweets, 200),
llmApiKey: llmApiKey,
},
() => {
document.getElementById("status").textContent =
"Settings saved successfully!";
}
);
} else {
document.getElementById("status").textContent =
"Please enter valid settings.";
}
});
document.getElementById("start").addEventListener("click", function () {
const waitingForRecomendations = "Waiting for Recomendations...";
// Clear the ollama response in storage
chrome.storage.local.set({
ollamaResponse: waitingForRecomendations,
});
document.getElementById("serverResponse").innerHTML =
waitingForRecomendations;
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: "startScrolling" });
});
});
document.getElementById("stop").addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: "stopScrolling" });
});
});
// Load the saved settings and Ollama response when the popup opens
setInterval(() => {
chrome.storage.local.get(
["tweetPostUrl", "scrollAmount", "ollamaResponse"],
(result) => {
if (result.ollamaResponse) {
const htmlContent = marked.parse(result.ollamaResponse);
if (result.ollamaResponse) {
const htmlContent = marked.parse(result.ollamaResponse);
document.getElementById("serverResponse").innerHTML = htmlContent;
}
}
}
);
}, 5000); // Check for changes every 5 second
chrome.storage.local.get(
["tweetPostUrl", "scrollAmount", "ollamaResponse"],
(result) => {
if (result.tweetPostUrl) {
document.getElementById("urlInput").value = result.tweetPostUrl;
}
if (result.scrollAmount) {
document.getElementById("scrollAmount").value = result.scrollAmount;
}
}
);