Skip to content

Commit 14fbbb6

Browse files
committed
Some changes
1 parent b2f5c87 commit 14fbbb6

19 files changed

Lines changed: 1016 additions & 724 deletions

Chrome/dashboard/dashboard-greasyfork.js

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { parseUserScriptMetadata } from "../utils/metadataParser.js";
2-
32
function setupGreasyfork(elements) {
43
if (!elements.button) return;
54

@@ -38,7 +37,7 @@ async function searchGreasyfork(elements) {
3837
const query = elements.searchInput.value.trim();
3938
if (!query) return;
4039

41-
elements.results.innerHTML = "";
40+
elements.results.textContent = "";
4241
elements.loading.style.display = "block";
4342

4443
try {
@@ -53,68 +52,82 @@ async function searchGreasyfork(elements) {
5352

5453
const scripts = await response.json();
5554

55+
elements.results.textContent = ""; // Safer than innerHTML reset
56+
5657
if (scripts.length === 0) {
57-
elements.results.innerHTML = `
58-
<div class="no-results">
59-
No scripts found for "${escapeHtml(
60-
query
61-
)}". Try a different search term.
62-
</div>
63-
`;
58+
const div = document.createElement("div");
59+
div.className = "no-results";
60+
div.textContent = `No scripts found for "${query}". Try a different search term.`;
61+
elements.results.appendChild(div);
6462
} else {
65-
elements.results.innerHTML = scripts
66-
.map((script) => createScriptCard(script))
67-
.join("");
68-
69-
elements.results
70-
.querySelectorAll(".import-greasy-fork")
71-
.forEach((button) => {
72-
button.addEventListener("click", () => {
73-
const codeUrl = button.closest(".script-card").dataset.codeUrl;
74-
importGreasyforkScript(codeUrl);
75-
});
76-
});
63+
for (const script of scripts) {
64+
const card = createScriptCard(script);
65+
elements.results.appendChild(card);
66+
}
7767
}
68+
69+
elements.results
70+
.querySelectorAll(".import-greasy-fork")
71+
.forEach((button) => {
72+
button.addEventListener("click", () => {
73+
const codeUrl = button.closest(".script-card").dataset.codeUrl;
74+
importGreasyforkScript(codeUrl);
75+
});
76+
});
7877
} catch (error) {
7978
console.error("Error searching Greasy Fork:", error);
80-
elements.results.innerHTML = `
81-
<div class="error-message">
82-
Error searching Greasy Fork: ${error.message}. Please try again later.
83-
</div>
84-
`;
79+
const errorDiv = document.createElement("div");
80+
errorDiv.className = "error-message";
81+
errorDiv.textContent = `Error searching Greasy Fork: ${error.message}. Please try again later.`;
82+
elements.results.appendChild(errorDiv);
8583
} finally {
8684
elements.loading.style.display = "none";
8785
}
8886
}
8987

9088
function createScriptCard(script) {
91-
const formatNumber = (num) => {
92-
return num ? num.toLocaleString() : "0";
93-
};
94-
95-
return `
96-
<div class="script-card" data-code-url="${escapeHtml(script.code_url)}">
97-
<h3>${escapeHtml(script.name)}</h3>
98-
<div class="script-card-meta">
99-
<span>👤 ${formatNumber(script.total_installs)}</span>
100-
<span>👍 ${formatNumber(script.good_ratings)}</span>
101-
<span>v${script.version || "1.0.0"}</span>
102-
</div>
103-
<p class="script-card-description">${escapeHtml(
104-
script.description || ""
105-
)}</p>
106-
<div class="script-card-actions">
107-
<a href="${
108-
script.url
109-
}" target="_blank" rel="noopener noreferrer" class="secondary">
110-
View on Greasy Fork
111-
</a>
112-
<button class="primary import-greasy-fork">
113-
Import
114-
</button>
115-
</div>
116-
</div>
89+
const formatNumber = (num) => (num ? num.toLocaleString() : "0");
90+
91+
const card = document.createElement("div");
92+
card.className = "script-card";
93+
card.dataset.codeUrl = script.code_url;
94+
95+
const title = document.createElement("h3");
96+
title.textContent = script.name;
97+
card.appendChild(title);
98+
99+
const meta = document.createElement("div");
100+
meta.className = "script-card-meta";
101+
meta.innerHTML = `
102+
<span>👤 ${formatNumber(script.total_installs)}</span>
103+
<span>👍 ${formatNumber(script.good_ratings)}</span>
104+
<span>v${script.version || "1.0.0"}</span>
117105
`;
106+
card.appendChild(meta);
107+
108+
const description = document.createElement("p");
109+
description.className = "script-card-description";
110+
description.textContent = script.description || "";
111+
card.appendChild(description);
112+
113+
const actions = document.createElement("div");
114+
actions.className = "script-card-actions";
115+
116+
const viewLink = document.createElement("a");
117+
viewLink.href = script.url;
118+
viewLink.target = "_blank";
119+
viewLink.rel = "noopener noreferrer";
120+
viewLink.className = "secondary";
121+
viewLink.textContent = "View on Greasy Fork";
122+
actions.appendChild(viewLink);
123+
124+
const importBtn = document.createElement("button");
125+
importBtn.className = "primary import-greasy-fork";
126+
importBtn.textContent = "Import";
127+
actions.appendChild(importBtn);
128+
129+
card.appendChild(actions);
130+
return card;
118131
}
119132

120133
async function importGreasyforkScript(codeUrl) {
@@ -195,4 +208,4 @@ async function importGreasyforkScript(codeUrl) {
195208
}
196209
}
197210

198-
export { setupGreasyfork };
211+
export { setupGreasyfork };

Chrome/dashboard/dashboard-ui.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ function updateWebsiteFilterOptions(scripts, websiteFilter) {
3333
}
3434
}
3535

36-
websiteFilter.innerHTML = '<option value="">All Websites</option>';
36+
// Clear all options
37+
while (websiteFilter.firstChild) {
38+
websiteFilter.removeChild(websiteFilter.firstChild);
39+
}
40+
// Add "All Websites" option
41+
const allOption = document.createElement("option");
42+
allOption.value = "";
43+
allOption.textContent = "All Websites";
44+
websiteFilter.appendChild(allOption);
3745

3846
Array.from(websites)
3947
.sort()
@@ -229,7 +237,11 @@ function createFaviconWrapper(hostname) {
229237
faviconImg.onerror = function () {
230238
console.warn(`Failed to load favicon for ${hostname}`);
231239
const fallbackText = hostname.replace(/\*\./g, "").charAt(0).toUpperCase();
232-
this.parentElement.innerHTML = `<div class='favicon-fallback'>${fallbackText}</div>`;
240+
const fallbackDiv = document.createElement("div");
241+
fallbackDiv.className = "favicon-fallback";
242+
fallbackDiv.textContent = fallbackText;
243+
this.parentElement.innerHTML = ""; // Clear previous content
244+
this.parentElement.appendChild(fallbackDiv);
233245
};
234246

235247
faviconWrapper.appendChild(faviconImg);
@@ -253,7 +265,10 @@ function createFaviconCounter(extraHosts) {
253265
favicon.src = `https://${hostname}/favicon.ico`;
254266
favicon.alt = "";
255267
favicon.onerror = () => {
256-
favicon.outerHTML = `<div class='favicon-fallback'>${hostname[0].toUpperCase()}</div>`;
268+
const fallbackDiv = document.createElement("div");
269+
fallbackDiv.className = "favicon-fallback";
270+
fallbackDiv.textContent = (hostname[0] || "?").toUpperCase();
271+
favicon.replaceWith(fallbackDiv);
257272
};
258273

259274
const domain = document.createElement("span");
@@ -280,7 +295,7 @@ function createActionsCell(script) {
280295
</svg>`,
281296
title: "Edit Script",
282297
handler: () => editScript(script.id),
283-
}
298+
},
284299
];
285300

286301
// check for update button
@@ -382,7 +397,7 @@ function showNotification(message, type = "info") {
382397
notification.append(icon, content, closeBtn);
383398
notificationContainer.appendChild(notification);
384399

385-
// remove
400+
// remove
386401
setTimeout(() => {
387402
if (notification.parentElement) {
388403
notification.classList.add("notification-hide");

0 commit comments

Comments
 (0)