|
|
|
|
@@ -1,24 +1,25 @@
|
|
|
|
|
const GITEA_INSTANCE = 'https://git.waifuboard.app';
|
|
|
|
|
const REPO_OWNER = 'ItsSkaiya';
|
|
|
|
|
const REPO_NAME = 'WaifuBoard-Extensions';
|
|
|
|
|
const API_URL = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/contents/extensions?ref=main`;
|
|
|
|
|
|
|
|
|
|
let DETECTED_BRANCH = 'main';
|
|
|
|
|
|
|
|
|
|
const API_URL_BASE = `${GITEA_INSTANCE}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/contents`;
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
const browseGrid = document.getElementById('marketplace-grid');
|
|
|
|
|
const installedGrid = document.getElementById('installed-grid');
|
|
|
|
|
|
|
|
|
|
const statTotal = document.getElementById('stat-total');
|
|
|
|
|
const statInstalled = document.getElementById('stat-installed');
|
|
|
|
|
|
|
|
|
|
const tabBrowse = document.getElementById('tab-browse');
|
|
|
|
|
const tabInstalled = document.getElementById('tab-installed');
|
|
|
|
|
const viewBrowse = document.getElementById('view-browse');
|
|
|
|
|
const viewInstalled = document.getElementById('view-installed');
|
|
|
|
|
const messageBar = document.getElementById('message-bar');
|
|
|
|
|
|
|
|
|
|
let allRemoteExtensions = [];
|
|
|
|
|
let installedExtensionsList = [];
|
|
|
|
|
|
|
|
|
|
const messageBar = document.getElementById('message-bar');
|
|
|
|
|
|
|
|
|
|
function showMessage(msg, type = 'success') {
|
|
|
|
|
if (!messageBar) return;
|
|
|
|
|
messageBar.textContent = msg;
|
|
|
|
|
@@ -34,56 +35,17 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
|
|
|
|
|
function showRestartToast() {
|
|
|
|
|
if (document.getElementById('restart-toast')) return;
|
|
|
|
|
|
|
|
|
|
const toast = document.createElement('div');
|
|
|
|
|
toast.id = 'restart-toast';
|
|
|
|
|
toast.style.cssText = `
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 20px;
|
|
|
|
|
right: 20px;
|
|
|
|
|
background: #1f2937;
|
|
|
|
|
border: 1px solid var(--accent);
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
padding: 1rem 1.5rem;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
|
|
|
|
|
z-index: 2000;
|
|
|
|
|
animation: slideUp 0.3s ease-out;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
toast.innerHTML = `
|
|
|
|
|
<div style="display:flex; flex-direction:column;">
|
|
|
|
|
<span style="color:#fff; font-weight:600;">Restart Required</span>
|
|
|
|
|
<span style="color:#9ca3af; font-size:0.8rem;">Changes will apply after restart.</span>
|
|
|
|
|
</div>
|
|
|
|
|
<button id="btn-restart-now" style="
|
|
|
|
|
background: var(--accent);
|
|
|
|
|
color: white;
|
|
|
|
|
border: none;
|
|
|
|
|
padding: 0.5rem 1rem;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
font-size: 0.85rem;
|
|
|
|
|
transition: 0.2s;
|
|
|
|
|
">Restart Now</button>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
toast.style.cssText = `position: fixed; bottom: 20px; right: 20px; background: #1f2937; border: 1px solid var(--accent); border-radius: 12px; padding: 1rem 1.5rem; display: flex; align-items: center; gap: 1rem; box-shadow: 0 10px 30px rgba(0,0,0,0.5); z-index: 2000; animation: slideUp 0.3s ease-out;`;
|
|
|
|
|
toast.innerHTML = `<div style="display:flex; flex-direction:column;"><span style="color:#fff; font-weight:600;">Restart Required</span><span style="color:#9ca3af; font-size:0.8rem;">Changes will apply after restart.</span></div><button id="btn-restart-now" style="background: var(--accent); color: white; border: none; padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 0.85rem; transition: 0.2s;">Restart Now</button>`;
|
|
|
|
|
document.body.appendChild(toast);
|
|
|
|
|
|
|
|
|
|
const btn = document.getElementById('btn-restart-now');
|
|
|
|
|
btn.onmouseover = () => btn.style.opacity = '0.9';
|
|
|
|
|
btn.onmouseout = () => btn.style.opacity = '1';
|
|
|
|
|
|
|
|
|
|
btn.onclick = () => {
|
|
|
|
|
if (window.api && typeof window.api.restartApp === 'function') {
|
|
|
|
|
window.api.restartApp();
|
|
|
|
|
} else {
|
|
|
|
|
console.error("Restart API not found in window.api");
|
|
|
|
|
alert("Please close and reopen the application manually.");
|
|
|
|
|
}
|
|
|
|
|
if (window.api && typeof window.api.restartApp === 'function') window.api.restartApp();
|
|
|
|
|
else alert("Please close and reopen the application manually.");
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -117,44 +79,67 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
|
|
|
|
|
async function fetchRemoteExtensions() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(API_URL);
|
|
|
|
|
if (!res.ok) throw new Error(`GitHub API Error: ${res.status}`);
|
|
|
|
|
let res = await fetch(API_URL_BASE);
|
|
|
|
|
|
|
|
|
|
if (res.status === 404) {
|
|
|
|
|
console.warn("Default branch failed, trying 'main'...");
|
|
|
|
|
DETECTED_BRANCH = 'main';
|
|
|
|
|
res = await fetch(`${API_URL_BASE}?ref=main`);
|
|
|
|
|
}
|
|
|
|
|
if (res.status === 404) {
|
|
|
|
|
console.warn("Main branch failed, trying 'master'...");
|
|
|
|
|
DETECTED_BRANCH = 'master';
|
|
|
|
|
res = await fetch(`${API_URL_BASE}?ref=master`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!res.ok) throw new Error(`Gitea API Error: ${res.status}`);
|
|
|
|
|
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
|
|
|
|
|
allRemoteExtensions = data.filter(item => item.name.endsWith('.js'));
|
|
|
|
|
renderBrowseGrid(allRemoteExtensions);
|
|
|
|
|
updateStats();
|
|
|
|
|
if (Array.isArray(data)) {
|
|
|
|
|
allRemoteExtensions = data.filter(item => item.name.endsWith('.js'));
|
|
|
|
|
renderBrowseGrid(allRemoteExtensions);
|
|
|
|
|
updateStats();
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error("Invalid API response format");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
if(browseGrid) browseGrid.innerHTML = `<div class="loading-state"><p style="color:#ef4444">Failed to load marketplace.<br>${e.message}</p></div>`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getRawUrl(filename) {
|
|
|
|
|
return `${GITEA_INSTANCE}/${REPO_OWNER}/${REPO_NAME}/raw/branch/main/${filename}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getExtensionDetails(url) {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(url);
|
|
|
|
|
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
|
|
|
|
const text = await res.text();
|
|
|
|
|
|
|
|
|
|
const baseUrlMatch = text.match(/baseUrl\s*=\s*["']([^"']+)["']/);
|
|
|
|
|
let baseUrl = baseUrlMatch ? baseUrlMatch[1] : null;
|
|
|
|
|
const regex = /(?:this\.|const\s+|let\s+|var\s+)?baseUrl\s*=\s*(["'`])(.*?)\1/i;
|
|
|
|
|
const match = text.match(regex);
|
|
|
|
|
|
|
|
|
|
if (baseUrl) {
|
|
|
|
|
let finalHostname = null;
|
|
|
|
|
if (match && match[2]) {
|
|
|
|
|
let rawUrl = match[2].trim();
|
|
|
|
|
if (!rawUrl.startsWith('http')) rawUrl = 'https://' + rawUrl;
|
|
|
|
|
try {
|
|
|
|
|
const urlObj = new URL(baseUrl);
|
|
|
|
|
baseUrl = urlObj.hostname;
|
|
|
|
|
} catch(e) {
|
|
|
|
|
console.warn("Invalid URL in extension:", baseUrl);
|
|
|
|
|
}
|
|
|
|
|
const urlObj = new URL(rawUrl);
|
|
|
|
|
finalHostname = urlObj.hostname;
|
|
|
|
|
} catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const classMatch = text.match(/class\s+(\w+)/);
|
|
|
|
|
const name = classMatch ? classMatch[1] : null;
|
|
|
|
|
|
|
|
|
|
let type = 'Image';
|
|
|
|
|
if (text.includes('type = "book-board"') || text.includes("type = 'book-board'")) {
|
|
|
|
|
type = 'Book';
|
|
|
|
|
}
|
|
|
|
|
if (text.includes('type = "book-board"') || text.includes("type = 'book-board'")) type = 'Book';
|
|
|
|
|
|
|
|
|
|
return { baseUrl, name, type };
|
|
|
|
|
return { baseUrl: finalHostname, name, type };
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return { baseUrl: null, name: null, type: 'Unknown' };
|
|
|
|
|
}
|
|
|
|
|
@@ -163,29 +148,32 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
async function createCard(item, isLocalOnly = false) {
|
|
|
|
|
const isInstalled = installedExtensionsList.includes(item.name);
|
|
|
|
|
|
|
|
|
|
const downloadUrl = item.download_url || null;
|
|
|
|
|
let sizeKB = item.size ? (item.size / 1024).toFixed(1) + ' KB' : 'Local';
|
|
|
|
|
const downloadUrl = getRawUrl(item.name);
|
|
|
|
|
|
|
|
|
|
let sizeKB = item.size ? (item.size / 1024).toFixed(1) + ' KB' : 'Local';
|
|
|
|
|
let iconUrl = '';
|
|
|
|
|
let displayName = item.name.replace('.js', '');
|
|
|
|
|
let typeLabel = 'Extension';
|
|
|
|
|
let typeClass = 'type-image';
|
|
|
|
|
|
|
|
|
|
const fallbackIcon = `data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22gray%22 stroke-width=%222%22><rect x=%223%22 y=%223%22 width=%2218%22 height=%2218%22 rx=%222%22/></svg>`;
|
|
|
|
|
|
|
|
|
|
if (downloadUrl) {
|
|
|
|
|
if (!isLocalOnly) {
|
|
|
|
|
const details = await getExtensionDetails(downloadUrl);
|
|
|
|
|
displayName = details.name || displayName;
|
|
|
|
|
const domain = details.baseUrl || 'github.com';
|
|
|
|
|
iconUrl = `https://www.google.com/s2/favicons?domain=${domain}&sz=128`;
|
|
|
|
|
|
|
|
|
|
if (details.baseUrl) {
|
|
|
|
|
iconUrl = `https://www.google.com/s2/favicons?domain=${details.baseUrl}&sz=128`;
|
|
|
|
|
} else {
|
|
|
|
|
iconUrl = `https://ui-avatars.com/api/?name=${displayName}&background=1f2937&color=fff&length=1`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (details.type === 'Book') {
|
|
|
|
|
typeLabel = 'Book Board';
|
|
|
|
|
typeClass = 'type-book';
|
|
|
|
|
} else {
|
|
|
|
|
typeLabel = 'Image Board';
|
|
|
|
|
typeClass = 'type-image';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
iconUrl = `https://ui-avatars.com/api/?name=${displayName}&background=18181b&color=fff&length=1`;
|
|
|
|
|
iconUrl = `https://ui-avatars.com/api/?name=${displayName}&background=1f2937&color=fff&length=1`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const card = document.createElement('div');
|
|
|
|
|
@@ -199,16 +187,14 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
const renderInner = (installed) => `
|
|
|
|
|
<div class="card-header-row">
|
|
|
|
|
<div class="ext-icon-box">
|
|
|
|
|
<img src="${iconUrl}" class="ext-icon" onerror="this.src='data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22gray%22 stroke-width=%222%22><rect x=%223%22 y=%223%22 width=%2218%22 height=%2218%22 rx=%222%22/></svg>'">
|
|
|
|
|
<img src="${iconUrl}" class="ext-icon" onerror="this.onerror=null; this.src='${fallbackIcon}'">
|
|
|
|
|
</div>
|
|
|
|
|
<span class="type-badge ${typeClass}">${typeLabel}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="ext-info">
|
|
|
|
|
<h3 class="ext-name">${displayName}</h3>
|
|
|
|
|
<div class="ext-filename">${item.name}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="card-footer">
|
|
|
|
|
<div class="ext-status-group">${installed ? `<span class="status-badge status-installed">${checkIcon} Installed</span>` : ''}
|
|
|
|
|
<span class="ext-size-badge">${sizeKB}</span>
|
|
|
|
|
@@ -233,12 +219,9 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
installedExtensionsList = installedExtensionsList.filter(n => n !== item.name);
|
|
|
|
|
card.innerHTML = renderInner(false);
|
|
|
|
|
updateStats();
|
|
|
|
|
|
|
|
|
|
if (tabInstalled.classList.contains('active')) {
|
|
|
|
|
card.remove();
|
|
|
|
|
if (installedGrid.children.length === 0) {
|
|
|
|
|
installedGrid.innerHTML = '<div class="loading-state"><p>No extensions installed.</p></div>';
|
|
|
|
|
}
|
|
|
|
|
if (installedGrid.children.length === 0) installedGrid.innerHTML = '<div class="loading-state"><p>No extensions installed.</p></div>';
|
|
|
|
|
}
|
|
|
|
|
showRestartToast();
|
|
|
|
|
} else {
|
|
|
|
|
@@ -250,6 +233,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
btn.innerHTML = '<svg class="spinner" viewBox="0 0 50 50"><circle cx="25" cy="25" r="20" fill="none" stroke="currentColor" stroke-width="5"></circle></svg>';
|
|
|
|
|
|
|
|
|
|
const success = await window.api.installExtension(item.name, downloadUrl);
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
installedExtensionsList.push(item.name);
|
|
|
|
|
card.innerHTML = renderInner(true);
|
|
|
|
|
@@ -258,6 +242,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
showRestartToast();
|
|
|
|
|
} else {
|
|
|
|
|
showMessage('Failed to install', 'error');
|
|
|
|
|
console.error("Install failed for URL:", downloadUrl);
|
|
|
|
|
btn.innerHTML = originalHTML;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -284,7 +269,6 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
installedGrid.innerHTML = '<div class="loading-state"><p>No extensions installed.</p></div>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const filename of installedExtensionsList) {
|
|
|
|
|
const remoteData = allRemoteExtensions.find(r => r.name === filename);
|
|
|
|
|
const item = remoteData || { name: filename, download_url: null, size: 0 };
|
|
|
|
|
|