-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
111 lines (96 loc) · 3.85 KB
/
popup.js
File metadata and controls
111 lines (96 loc) · 3.85 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
// Check if a URL is a Cloudflare Workflows page
function isWorkflowsPage(url) {
return url.includes('cloudflare.com') && url.includes('workers/workflows');
}
// When the popup is loaded
document.addEventListener('DOMContentLoaded', function() {
// Get references to DOM elements
const hiddenList = document.getElementById('hidden-list');
const emptyMessage = document.getElementById('empty-message');
const clearAllBtn = document.getElementById('clear-all');
const forceAddBtn = document.getElementById('force-add');
const statusEl = document.getElementById('status-message');
// Get the active tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const activeTab = tabs[0];
// Only proceed if we're on a cloudflare workflows page
if (isWorkflowsPage(activeTab.url)) {
// Get the list of hidden workflows from the content script
chrome.tabs.sendMessage(activeTab.id, {action: 'getHiddenWorkflows'}, function(response) {
if (response && response.hiddenWorkflows) {
updateHiddenList(response.hiddenWorkflows);
}
});
// Enable the buttons
clearAllBtn.disabled = false;
forceAddBtn.disabled = false;
} else {
// Not on Cloudflare Workflows page
hiddenList.innerHTML = '';
emptyMessage.textContent = 'This extension only works on the Cloudflare Workflows dashboard page.';
emptyMessage.style.display = 'block';
// Disable the buttons
clearAllBtn.disabled = true;
forceAddBtn.disabled = true;
// Show a helpful message
statusEl.textContent = 'Please navigate to the Cloudflare Workflows page to use this extension.';
statusEl.style.display = 'block';
statusEl.style.color = '#f44336'; // Red color for warning
}
});
// Clear all hidden workflows button
clearAllBtn.addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const activeTab = tabs[0];
if (isWorkflowsPage(activeTab.url)) {
chrome.tabs.sendMessage(activeTab.id, {action: 'clearAllHidden'}, function(response) {
if (response && response.success) {
updateHiddenList([]);
// Show success message
statusEl.textContent = 'All workflows are now visible!';
statusEl.style.display = 'block';
statusEl.style.color = '#4CAF50'; // Green color for success
setTimeout(() => {
statusEl.style.display = 'none';
}, 3000);
}
});
}
});
});
// Force add hide buttons
forceAddBtn.addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const activeTab = tabs[0];
if (isWorkflowsPage(activeTab.url)) {
chrome.tabs.sendMessage(activeTab.id, {action: 'forceAddButtons'}, function(response) {
if (response && response.success) {
statusEl.textContent = 'Hide buttons added!';
statusEl.style.display = 'block';
statusEl.style.color = '#4CAF50'; // Green color for success
setTimeout(() => {
statusEl.style.display = 'none';
}, 3000);
}
});
}
});
});
// Function to update the list of hidden workflows in the popup
function updateHiddenList(hiddenWorkflows) {
if (hiddenWorkflows.length === 0) {
hiddenList.innerHTML = '';
emptyMessage.textContent = 'No workflows are currently hidden.';
emptyMessage.style.display = 'block';
} else {
emptyMessage.style.display = 'none';
// Create list items for each hidden workflow
hiddenList.innerHTML = '';
hiddenWorkflows.forEach(function(workflow) {
const li = document.createElement('li');
li.textContent = workflow;
hiddenList.appendChild(li);
});
}
}
});