-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopup.js
More file actions
144 lines (124 loc) · 4.09 KB
/
Copy pathpopup.js
File metadata and controls
144 lines (124 loc) · 4.09 KB
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
/**
* lolnuked StreamGuard - Popup Interface
*
* Created by: Daniel "CEO of the XRPL" Keller
* Twitter/X: @daniel_wwf (https://x.com/daniel_wwf)
*
* ATTRIBUTION REQUIRED: This attribution MUST NOT be removed.
*/
// Popup settings glue
const K_ENABLED = "pfam_enabled";
const K_ACTION = "pfam_action"; // "highlight" | "delete_ui" | "ban_ui"
const K_DELAY = "pfam_delay_ms";
const K_REASON = "pfam_ban_reason";
const defaults = {
[K_ENABLED]: true,
[K_ACTION]: "viewer_mode",
[K_DELAY]: 200, // 0.2 seconds default for ban/delete modes
[K_REASON]: "Spam"
};
const $ = sel => document.querySelector(sel);
function load() {
chrome.storage.sync.get(defaults, res => {
$("#enabled").checked = !!res[K_ENABLED];
$("#action").value = res[K_ACTION];
$("#delay").value = String(res[K_DELAY]);
$("#reason").value = res[K_REASON];
// Set delay visibility based on the LOADED action value (not HTML default)
updateDelayVisibility(res[K_ACTION]);
});
// Load tab status
loadTabStatus();
}
function bind() {
$("#enabled").addEventListener("change", e => {
chrome.storage.sync.set({ [K_ENABLED]: e.target.checked });
});
$("#action").addEventListener("change", e => {
chrome.storage.sync.set({ [K_ACTION]: e.target.value });
// Hide delay setting for viewer mode (it's instant)
updateDelayVisibility(e.target.value);
});
$("#delay").addEventListener("change", e => {
chrome.storage.sync.set({ [K_DELAY]: Number(e.target.value) });
});
$("#reason").addEventListener("change", e => {
chrome.storage.sync.set({ [K_REASON]: e.target.value });
});
// Force activate button
$("#force-activate").addEventListener("click", () => {
chrome.tabs?.query({active: true, currentWindow: true}, (tabs) => {
if (!tabs || !tabs[0]) return;
chrome.tabs?.sendMessage(tabs[0].id, {action: "forceActivate"}, () => {
// Clear any Chrome runtime errors
if (chrome.runtime.lastError) {
console.log("Could not send forceActivate message:", chrome.runtime.lastError.message);
return;
}
// Reload status after activation
setTimeout(loadTabStatus, 500);
});
});
});
// Manage triggers button
$("#manage-triggers").addEventListener("click", () => {
chrome.windows?.create({
url: "triggers.html",
type: "popup",
width: 450,
height: 500
});
});
}
function loadTabStatus() {
chrome.tabs?.query({active: true, currentWindow: true}, (tabs) => {
if (!tabs || !tabs[0]) {
$("#tab-text").textContent = "No active tab";
return;
}
chrome.tabs?.sendMessage(tabs[0].id, {action: "getTabStatus"}, (response) => {
// Clear any Chrome runtime errors
if (chrome.runtime.lastError) {
// Content script not loaded or not on pump.fun
$("#tab-text").textContent = "Not on pump.fun or extension not loaded";
return;
}
if (response) {
updateTabStatusUI(response.isActive, response.tabId);
} else {
// Fallback if content script not ready
$("#tab-text").textContent = "Extension loading...";
}
});
});
}
function updateTabStatusUI(isActive, tabId) {
const indicator = $("#tab-indicator");
const text = $("#tab-text");
const button = $("#force-activate");
if (isActive) {
indicator.textContent = "🟢";
text.textContent = "Active on this tab";
button.style.display = "none";
} else {
indicator.textContent = "⚪";
text.textContent = "Inactive (dormant)";
button.style.display = "block";
}
}
function updateDelayVisibility(actionMode) {
const delayRow = $("#delay-row");
const delayMessage = $("#delay-message");
if (actionMode === "viewer_mode") {
// Show message for viewer mode (no delay options)
delayRow.style.display = "none";
delayMessage.style.display = "flex";
} else {
// Show delay selector for other modes
delayRow.style.display = "flex";
delayMessage.style.display = "none";
}
}
document.addEventListener("DOMContentLoaded", () => {
load(); bind();
});