Skip to content

Commit e75d203

Browse files
committed
better design for the in explorer import button
1 parent 4a7f6f5 commit e75d203

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

assets/changes.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ <h2>V4.1 -- What's New:</h2>
1010
<h3 class="changelog-version">Commits on May 18, 2025</h3>
1111
<p class="changelog-date">May 18, 2025</p>
1212
<ul>
13+
<li><strong>[NONEYET]</strong> better design for the in explorer import button</li>
1314
<li><strong>[HOTFIX]</strong> fixed jsdelivr and github urls failing in 404</li>
1415
<li><strong>[1cb81cc] Fck ton of refactoring: 4.0 -> 4.1</strong><br>
1516
refactor: script.js, repoexplorer.js, styles.css, repoexplorer.css

css/repoexplorer.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@
281281
.fe-import-model-btn {
282282
margin-left: auto;
283283
padding: 0.3rem 0.6rem;
284-
font-size: 0.8rem;
284+
font-size: 1rem;
285+
font-weight: 900;
285286
border-radius: var(--border-radius-small);
286287
color: var(--text-primary);
287288
background-color: var(--accent-secondary);

js/repoexplorer.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,17 @@ document.addEventListener('DOMContentLoaded', () => {
277277
// Check for Live2D model file using the refined regex
278278
if (item.type === 'file' && MODEL_FILE_REGEX.test(item.name)) {
279279
const importBtn = document.createElement('button');
280-
importBtn.textContent = 'Import Model';
281280
importBtn.className = 'fe-import-model-btn';
282281
importBtn.title = `Import ${item.name} to Live2D Viewer`;
282+
283+
const importIcon = document.createElement('i');
284+
importIcon.className = 'fas fa-file-import';
285+
importIcon.setAttribute('aria-hidden', 'true');
286+
importIcon.style.marginRight = '0.4em'; // Add some space between icon and text
287+
288+
importBtn.appendChild(importIcon); // Icon first
289+
importBtn.appendChild(document.createTextNode('Import Model')); // Then text
290+
283291
importBtn.addEventListener('click', (e) => {
284292
e.stopPropagation(); // Prevent li click event
285293
handleImportModel(item);
@@ -372,7 +380,7 @@ document.addEventListener('DOMContentLoaded', () => {
372380
showLoaderFE(true);
373381

374382
const jsDelivrUrl = `${JSDELIVR_CDN_BASE}/${currentOwner}/${currentRepo}${DEFAULT_BRANCHE}/${fileItem.path}`;
375-
const rawGitHubUrl = fileItem.open_url; // open_url is usually the raw content URL
383+
const rawGitHubUrl = fileItem.download_url; // download_url is usually the raw content URL (GitHub API preference)
376384

377385
try {
378386
const extension = fileItem.name.split('.').pop().toLowerCase();
@@ -419,16 +427,24 @@ document.addEventListener('DOMContentLoaded', () => {
419427
// Add "Import Model" button to preview if applicable
420428
if (fileItem.type === 'file' && MODEL_FILE_REGEX.test(fileItem.name)) {
421429
const importBtnPreview = document.createElement('button');
422-
importBtnPreview.textContent = 'Import Model';
423430
importBtnPreview.className = 'fe-import-model-btn-preview';
424431
importBtnPreview.title = `Import ${fileItem.name} to Live2D Viewer`;
432+
433+
const importIconPreview = document.createElement('i');
434+
importIconPreview.className = 'fas fa-file-import';
435+
importIconPreview.setAttribute('aria-hidden', 'true');
436+
importIconPreview.style.marginRight = '0.4em';
437+
438+
importBtnPreview.appendChild(importIconPreview);
439+
importBtnPreview.appendChild(document.createTextNode('Import Model'));
440+
425441
importBtnPreview.addEventListener('click', () => {
426442
handleImportModel(fileItem, fileSourceUrl); // Pass the successful source URL
427443
});
428444
previewActions.appendChild(importBtnPreview);
429445
}
430446

431-
} catch (error) { // Didn't happen yet, not really tested
447+
} catch (error) {
432448
console.error('File preview error:', error);
433449
previewContent.innerHTML = `<p class="fe-placeholder-text fe-error-message">Error loading preview: ${error.message}</p>`;
434450
// Add a link to view on GitHub as a last resort for any error
@@ -547,9 +563,9 @@ document.addEventListener('DOMContentLoaded', () => {
547563
* @param {string|null} [sourceUrlOverride=null] - Optional override for the model URL.
548564
*/
549565
function handleImportModel(fileItem, sourceUrlOverride = null) {
550-
// Prefer open_url if available and no override, as it's the direct raw content link.
551-
// Fallback to jsDelivr if open_url is not present (should be rare for files).
552-
const modelUrl = sourceUrlOverride || fileItem.open_url || `${JSDELIVR_CDN_BASE}/${currentOwner}/${currentRepo}${DEFAULT_BRANCHE}/${fileItem.path}`;
566+
// Prefer download_url if available and no override, as it's the direct raw content link.
567+
// Fallback to jsDelivr if download_url is not present (should be rare for files).
568+
const modelUrl = sourceUrlOverride || fileItem.download_url || `${JSDELIVR_CDN_BASE}/${currentOwner}/${currentRepo}${DEFAULT_BRANCHE}/${fileItem.path}`;
553569
console.log(`Attempting to import Live2D Model: ${modelUrl}`);
554570

555571
if (window.loadLive2DModel && typeof window.loadLive2DModel === 'function') {

ztodo.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ Some Day:
55

66
Priority:
77
- Preview content in explorer tile as row, left/right
8-
- Improve import model button in explorer
98
- Cutom look for title="" like tool tip
109
- Smoother animations
11-
- Search in repoexplorer when beginning to type
1210

1311
Other:
1412
- Refactor all files 1st, 2nd, 3rd(css), 4th, 5th, 6th,

0 commit comments

Comments
 (0)