4 Commits

7 changed files with 361 additions and 113 deletions

View File

@@ -68,6 +68,7 @@ function createWindow() {
mainWindow.loadFile('views/index.html'); mainWindow.loadFile('views/index.html');
mainWindow.setMenu(null); mainWindow.setMenu(null);
mainWindow.on('closed', () => { headlessBrowser.forceKill(); });
} }
app.whenReady().then(() => { app.whenReady().then(() => {

View File

@@ -1,3 +1,14 @@
const gallery = document.getElementById('content-gallery');
if (gallery) {
const ro = new ResizeObserver(() => {
const items = gallery.querySelectorAll('.image-entry[data-type="image"]');
items.forEach(item => resizeMasonryItem(item));
relayoutMasonry(gallery);
});
ro.observe(gallery);
}
let masonryFrameRunning = false; let masonryFrameRunning = false;
function scheduleMasonryRelayout(grid) { function scheduleMasonryRelayout(grid) {
if (masonryFrameRunning) return; if (masonryFrameRunning) return;
@@ -9,11 +20,6 @@ function scheduleMasonryRelayout(grid) {
}); });
} }
export function triggerMasonryRelayout(gallery) {
if (!gallery) return;
setTimeout(() => relayoutMasonry(gallery), 350);
}
export function createImageCard(id, tags, imageUrl, thumbnailUrl, options = {}) { export function createImageCard(id, tags, imageUrl, thumbnailUrl, options = {}) {
const { const {
showMessage, showMessage,
@@ -175,17 +181,6 @@ function updateHeartIcon(btn, isFavorited) {
btn.title = isFavorited ? "Remove from Favorites" : "Add to Favorites"; btn.title = isFavorited ? "Remove from Favorites" : "Add to Favorites";
} }
function getSidebarClosedWidth() {
const s = document.querySelector('.sidebar');
if (!s) return 0;
return parseFloat(
getComputedStyle(document.documentElement)
.getPropertyValue('--sidebar-width-collapsed')
);
}
function resizeMasonryItem(item) { function resizeMasonryItem(item) {
if (item.dataset.type === 'book') return; if (item.dataset.type === 'book') return;
@@ -194,30 +189,19 @@ function resizeMasonryItem(item) {
const img = item.querySelector("img"); const img = item.querySelector("img");
if (!img || !img.complete || img.naturalWidth === 0) return; if (!img || !img.complete || img.naturalWidth === 0) return;
const gridCurrent = grid.getBoundingClientRect().width; const simulatedWidth = item.getBoundingClientRect().width;
const sidebar = document.querySelector(".sidebar");
const sidebarExpanded = parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--sidebar-width-expanded"));
const sidebarCollapsed = parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--sidebar-width-collapsed"));
const gridClosedWidth = gridCurrent - (sidebarExpanded - sidebarCollapsed);
const currentItemWidth = item.getBoundingClientRect().width;
const simulatedWidth = (currentItemWidth / gridCurrent) * gridClosedWidth;
const gridStyles = getComputedStyle(grid); const gridStyles = getComputedStyle(grid);
const rowHeight = parseInt(gridStyles.gridAutoRows); const rowHeight = parseInt(gridStyles.gridAutoRows);
const rowGap = parseInt(gridStyles.gap); const rowGap = parseInt(gridStyles.gap);
const imageHeight = (img.naturalHeight / img.naturalWidth) * simulatedWidth; const totalHeight = (img.naturalHeight / img.naturalWidth) * simulatedWidth;
const totalHeight = imageHeight;
const rowSpan = Math.ceil((totalHeight + rowGap) / (rowHeight + rowGap)); const rowSpan = Math.ceil((totalHeight + rowGap) / (rowHeight + rowGap));
item.style.gridRowEnd = `span ${rowSpan}`; item.style.gridRowEnd = `span ${rowSpan}`;
item.style.height = "auto"; item.style.height = "auto";
} }
function relayoutMasonry(grid) { function relayoutMasonry(grid) {
if (!grid) return; if (!grid) return;
const items = grid.querySelectorAll('.image-entry[data-type="image"]'); const items = grid.querySelectorAll('.image-entry[data-type="image"]');

View File

@@ -2,7 +2,7 @@ import { populateSources } from './extensions/load-extensions.js';
import { setupGlobalKeybinds } from './utils/keybinds.js'; import { setupGlobalKeybinds } from './utils/keybinds.js';
import { getDomElements } from './utils/dom-loader.js'; import { getDomElements } from './utils/dom-loader.js';
import { performSearch, loadMoreResults } from './modules/search-handler.js'; import { performSearch, loadMoreResults } from './modules/search-handler.js';
import { createImageCard, createBookCard, populateTagModal, triggerMasonryRelayout } from './content/image-handler.js'; import { createImageCard, createBookCard, populateTagModal } from './content/image-handler.js';
import { showMessage as uiShowMessage } from './modules/ui-utils.js'; import { showMessage as uiShowMessage } from './modules/ui-utils.js';
import { applyLayoutToGallery } from './modules/layout-manager.js'; import { applyLayoutToGallery } from './modules/layout-manager.js';

View File

@@ -176,6 +176,22 @@ class HeadlessBrowser {
`; `;
await win.webContents.executeJavaScript(script); await win.webContents.executeJavaScript(script);
} }
forceKill() {
try {
if (this.win && !this.win.isDestroyed()) {
const wc = this.win.webContents;
try { wc.stop(); } catch (_) {}
try { wc.close(); } catch (_) {}
try { wc.destroy(); } catch (_) {}
this.win.destroy();
}
} catch (_) {}
this.win = null;
}
} }
module.exports = new HeadlessBrowser(); module.exports = new HeadlessBrowser();

View File

@@ -11,46 +11,53 @@
<body> <body>
<aside class="sidebar"> <aside class="sidebar">
<a href="index.html" class="nav-button" title="Image Boards"> <a href="index.html" class="nav-button" title="Image Boards">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="7" height="7"></rect> <rect x="3" y="3" width="7" height="7"></rect>
<rect x="14" y="3" width="7" height="7"></rect> <rect x="14" y="3" width="7" height="7"></rect>
<rect x="14" y="14" width="7" height="7"></rect> <rect x="14" y="14" width="7" height="7"></rect>
<rect x="3" y="14" width="7" height="7"></rect> <rect x="3" y="14" width="7" height="7"></rect>
</svg> </svg>
<span>Back To Home</span> <span>Back To Home</span>
</a> </a>
<button class="nav-button active" title="Emulator"> <button class="nav-button active" title="Emulator">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-xml-icon lucide-code-xml"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-xml-icon lucide-code-xml"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg>
<span>Emulator</span> <span>Emulator</span>
</button> </button>
<button class="nav-button" title="Reset" onclick="window.location.reload()"> <button class="nav-button" title="Reset" onclick="window.location.reload()">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash2-icon lucide-trash-2"><path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash2-icon lucide-trash-2"><path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
<span>Reset</span> <span>Reset</span>
</button> </button>
</aside> </aside>
<div class="main-wrapper"> <div class="main-wrapper">
<header class="top-header"> <header class="top-header">
<button id="hamburger-btn" class="hamburger"></button> <button id="hamburger-btn" class="hamburger"></button>
<h3>Extension Emulator</h3> <h3>Extension Emulator</h3>
</header> </header>
<div class="emulator-container"> <div class="emulator-container">
<div class="editor-pane"> <div class="editor-pane">
<div class="control-bar" style="background: transparent; border: none; padding: 0;"> <div class="control-bar" style="background: transparent; border: none; padding: 0;">
<h4 style="margin:0">Extension Code</h4> <h4 style="margin:0">Extension Code</h4>
<span style="font-size: 0.8rem; color: var(--text-tertiary); margin-left: auto;">Paste your .js file <span style="font-size: 0.8rem; color: var(--text-tertiary); margin-left: auto;">
here</span> Paste your .js file here
</div> </span>
<textarea id="code-input" class="code-editor" spellcheck="false"
placeholder="// Paste your extension class here..."></textarea>
</div> </div>
<textarea id="code-input" class="code-editor" spellcheck="false"
placeholder="// Paste your extension class here..."></textarea>
</div>
<div class="preview-pane"> <div class="preview-pane">
<div class="control-bar">
<div class="control-bar" id="main-control-bar">
<button id="mobile-controls-toggle" class="btn-run mobile-only">
Options
</button>
<div id="desktop-controls" class="control-group-wrapper">
<div class="control-group"> <div class="control-group">
<label>Function</label> <label>Function</label>
<select id="func-select" class="control-input"> <select id="func-select" class="control-input">
@@ -64,7 +71,7 @@
<div class="control-group"> <div class="control-group">
<label>Query / ID / URL</label> <label>Query / ID / URL</label>
<input type="text" id="arg-input" class="control-input" value="" <input type="text" id="arg-input" class="control-input" value=""
placeholder="Search query or ID"> placeholder="Search query or ID">
</div> </div>
<div class="control-group" style="max-width: 80px;"> <div class="control-group" style="max-width: 80px;">
@@ -74,31 +81,121 @@
<button class="btn-run" id="run-btn">Run</button> <button class="btn-run" id="run-btn">Run</button>
</div> </div>
</div>
<div style="display: flex; flex-direction: column; flex: 1; overflow: hidden; position: relative;"> <div style="display: flex; flex-direction: column; flex: 1; overflow: hidden; position: relative;">
<div class="tabs"> <div class="tabs">
<button class="tab-btn active" onclick="switchTab('visual')">Visual</button> <button class="tab-btn active" onclick="switchTab('visual')">Visual</button>
<button class="tab-btn" onclick="switchTab('json')">JSON</button> <button class="tab-btn" onclick="switchTab('json')">JSON</button>
<button class="tab-btn" onclick="switchTab('console')">Console</button> <button class="tab-btn" onclick="switchTab('console')">Console</button>
</div> </div>
<div id="output-visual" class="output-area"> <div id="output-visual" class="output-area">
<div class="loading-state hidden">Loading...</div> <div class="loading-state hidden">Loading...</div>
<div id="visual-container"></div> <div id="visual-container"></div>
</div> </div>
<div id="output-json" class="output-area hidden"> <div id="output-json" class="output-area hidden">
<pre id="json-content"></pre> <pre id="json-content"></pre>
</div> </div>
<div id="output-console" class="output-area hidden"> <div id="output-console" class="output-area hidden">
<div id="console-content"></div> <div id="console-content"></div>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
<script src="../src/emulator/emulator.js"></script> <div id="mobile-controls-overlay"></div>
<script src="../src/hamburger.js"></script> <div id="mobile-controls-drawer">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:1rem;">
<h4 style="margin:0; color:var(--text-primary);">Run Options</h4>
<button id="close-drawer-btn" style="background:none;border:none;font-size:1.8rem;cursor:pointer;color:var(--text-secondary);">
X
</button>
</div>
<div class="control-group-wrapper">
<div class="control-group">
<label>Function</label>
<select id="func-select-mobile" class="control-input">
<option value="fetchSearchResult">fetchSearchResult (Search)</option>
<option value="fetchInfo">fetchInfo (Image Details)</option>
<option value="findChapters">findChapters (Manga/Novel)</option>
<option value="findChapterPages">findChapterPages (Read)</option>
</select>
</div>
<div class="control-group">
<label>Query / ID / URL</label>
<input type="text" id="arg-input-mobile" class="control-input" placeholder="Search query or ID">
</div>
<div class="control-group">
<label>Page</label>
<input type="number" id="page-input-mobile" class="control-input" value="1" min="1">
</div>
<button class="btn-run" id="run-btn-mobile">Run</button>
</div>
</div>
<script src="../src/emulator/emulator.js"></script>
<script src="../src/hamburger.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const toggleBtn = document.getElementById('mobile-controls-toggle');
const drawer = document.getElementById('mobile-controls-drawer');
const overlay = document.getElementById('mobile-controls-overlay');
const closeBtn = document.getElementById('close-drawer-btn');
const funcSelect = document.getElementById('func-select');
const argInput = document.getElementById('arg-input');
const pageInput = document.getElementById('page-input');
const runBtn = document.getElementById('run-btn');
const funcMobile = document.getElementById('func-select-mobile');
const argMobile = document.getElementById('arg-input-mobile');
const pageMobile = document.getElementById('page-input-mobile');
const runMobile = document.getElementById('run-btn-mobile');
const syncDesktopToMobile = () => {
funcMobile.value = funcSelect.value;
argMobile.value = argInput.value;
pageMobile.value = pageInput.value;
};
const syncMobileToDesktop = () => {
funcSelect.value = funcMobile.value;
argInput.value = argMobile.value;
pageInput.value = pageMobile.value;
};
toggleBtn?.addEventListener('click', () => {
syncDesktopToMobile();
drawer.classList.add('open');
overlay.classList.add('open');
});
const closeDrawer = () => {
syncMobileToDesktop();
drawer.classList.remove('open');
overlay.classList.remove('open');
};
closeBtn?.addEventListener('click', closeDrawer);
overlay?.addEventListener('click', closeDrawer);
document.addEventListener('keydown', e => {
if (e.key === 'Escape') closeDrawer();
});
runMobile?.addEventListener('click', () => {
syncMobileToDesktop();
closeDrawer();
runBtn.click();
});
});
</script>
</body> </body>
</html> </html>

View File

@@ -3,8 +3,8 @@
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
gap: 1.5rem; gap: 1.5rem;
height: calc(100vh - var(--header-height)); height: calc(100vh - var(--header-height));
padding: 1rem 2rem 2rem 2rem; padding: 1rem 2rem 2rem;
overflow: auto; overflow: hidden;
} }
.editor-pane, .editor-pane,
@@ -207,11 +207,68 @@ pre {
@media (max-width: 767px) { @media (max-width: 767px) {
.emulator-container { .emulator-container {
grid-template-columns: 1fr; grid-template-columns: 1fr;
grid-template-rows: minmax(250px, 40vh) minmax(400px, 1fr); grid-template-rows: minmax(220px, 35vh) 1fr;
gap: 1rem; gap: 1rem;
padding: 1rem; padding: 0.75rem;
height: auto; height: auto;
overflow-y: auto; min-height: calc(100vh - var(--header-height));
overflow: visible;
}
#mobile-controls-toggle {
display: block !important;
width: 100%;
}
#desktop-controls {
display: none;
}
.control-bar {
padding: 0.75rem;
justify-content: center;
}
.tabs {
flex-shrink: 0;
}
#visual-container {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
gap: 0.75rem;
padding: 0.5rem 0;
}
.visual-card {
width: calc(50% - 0.375rem);
max-width: 180px;
margin: 0;
}
.visual-card img {
height: 220px;
}
.visual-card .title {
font-size: 0.8rem;
padding: 0.45rem;
}
.visual-chapter {
padding: 0.85rem 0.75rem;
font-size: 0.95rem;
}
#console-content,
#json-content pre {
font-size: 0.82rem;
line-height: 1.4;
}
.loading-state {
font-size: 1rem;
} }
.editor-pane, .editor-pane,
@@ -230,14 +287,22 @@ pre {
.preview-pane { .preview-pane {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
overflow: visible; height: auto;
min-height: 0;
}
.preview-pane > div:nth-child(2) {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
} }
.code-editor { .code-editor {
min-height: 200px;
max-height: 40vh;
font-size: 13px; font-size: 13px;
padding: 0.75rem; padding: 0.75rem;
min-height: 200px;
max-height: 35vh;
} }
.control-bar { .control-bar {
@@ -288,9 +353,10 @@ pre {
} }
.output-area { .output-area {
padding: 0.75rem; flex: 1;
overflow-y: auto !important;
min-height: 300px; min-height: 300px;
overflow: auto; padding: 0.75rem;
} }
.visual-card { .visual-card {
@@ -367,4 +433,60 @@ pre {
.visual-card img { .visual-card img {
height: 180px; height: 180px;
} }
}
.control-group-wrapper {
display: flex;
gap: 0.5rem;
align-items: end;
flex-wrap: wrap;
width: 100%;
}
#mobile-controls-drawer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: var(--bg-surface);
border-top: 1px solid var(--border);
border-radius: var(--radius-md) var(--radius-md) 0 0;
padding: 1rem;
transform: translateY(100%);
transition: transform 0.25s ease;
z-index: 1000;
box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}
#mobile-controls-drawer.open {
transform: translateY(0);
}
#mobile-controls-drawer .control-group-wrapper {
flex-direction: column;
gap: 1rem;
}
#mobile-controls-drawer .control-group {
min-width: 0;
}
#mobile-controls-drawer .btn-run {
width: 100%;
margin-top: 0.5rem;
}
#mobile-controls-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
opacity: 0;
pointer-events: none;
transition: opacity 0.25s;
z-index: 999;
}
#mobile-controls-overlay.open {
opacity: 1;
pointer-events: auto;
} }

View File

@@ -306,7 +306,6 @@ a:active {
border-radius: var(--radius-md); border-radius: var(--radius-md);
overflow: hidden; overflow: hidden;
position: relative; position: relative;
background: var(--bg-surface);
break-inside: avoid; break-inside: avoid;
transition: transform 0.2s; transition: transform 0.2s;
cursor: zoom-in; cursor: zoom-in;
@@ -333,21 +332,38 @@ a:active {
min-height: unset; min-height: unset;
} }
.image-entry::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 50%);
pointer-events: none;
opacity: 0;
transition: opacity 0.25s ease;
z-index: 1;
border-radius: var(--radius-md);
}
.image-buttons { .image-buttons {
position: absolute; position: absolute;
bottom: 0; bottom: 0.75rem;
left: 0; right: 0.75rem;
width: 100%; left: auto;
padding: 2rem 1rem 1rem 1rem;
background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
display: flex; display: flex;
justify-content: flex-end;
gap: 0.5rem; gap: 0.5rem;
z-index: 2;
opacity: 0; opacity: 0;
transition: 0.2s; transition: opacity 0.25s ease;
top: auto; pointer-events: none;
right: auto; }
flex-direction: row;
.image-buttons button {
pointer-events: all;
}
.image-entry:hover::before,
.image-entry:hover .image-buttons {
opacity: 1;
} }
.image-entry:hover .image-buttons { .image-entry:hover .image-buttons {
@@ -720,7 +736,7 @@ input[type="radio"] {
.gallery-masonry { .gallery-masonry {
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 0.75rem; gap: 0.85rem;
} }
.image-entry:not([data-type="book"]):hover { .image-entry:not([data-type="book"]):hover {
@@ -728,18 +744,30 @@ input[type="radio"] {
} }
.image-buttons { .image-buttons {
opacity: 0.8; opacity: 1 !important;
padding: 1.5rem 0.75rem 0.75rem 0.75rem; bottom: 8%;
right: 10px;
left: 10px;
justify-content: flex-end;
gap: 10px;
pointer-events: all;
} }
.image-buttons button { .image-buttons button {
width: 36px; width: 44px;
height: 36px; height: 44px;
background: rgba(0, 0, 0, 0.7);
border-width: 2px;
} }
.image-buttons button svg { .image-buttons button svg {
width: 18px; width: 20px;
height: 18px; height: 20px;
}
.image-buttons button:active {
transform: scale(0.95);
background: var(--accent);
} }
#source-list { #source-list {