Spaces:
Running
Running
Fix missing JS functions changeTextSize toggleFavsView SHOWING_FAVS
Browse files- index.html +96 -0
index.html
CHANGED
|
@@ -740,6 +740,102 @@ function runAiAnalysis() {
|
|
| 740 |
});
|
| 741 |
}
|
| 742 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 743 |
// Init
|
| 744 |
try {
|
| 745 |
var savedSize = localStorage.getItem('text_size');
|
|
|
|
| 740 |
});
|
| 741 |
}
|
| 742 |
|
| 743 |
+
|
| 744 |
+
// === Global State & Favorites & Text Size ===
|
| 745 |
+
var FAVS = {};
|
| 746 |
+
var SHOWING_FAVS = false;
|
| 747 |
+
|
| 748 |
+
try {
|
| 749 |
+
FAVS = JSON.parse(localStorage.getItem('hf_favs') || '{}');
|
| 750 |
+
} catch(e) {}
|
| 751 |
+
|
| 752 |
+
function changeTextSize(val) {
|
| 753 |
+
document.documentElement.style.fontSize = val;
|
| 754 |
+
try { localStorage.setItem('text_size', val); } catch(e) {}
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
function updateFavCount() {
|
| 758 |
+
var count = Object.keys(FAVS).length;
|
| 759 |
+
var el = document.getElementById('fav-count');
|
| 760 |
+
if (el) el.textContent = count;
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
function toggleFav(id, cat, lib) {
|
| 764 |
+
if (FAVS[id]) {
|
| 765 |
+
delete FAVS[id];
|
| 766 |
+
toast('已從收藏夾移除');
|
| 767 |
+
} else {
|
| 768 |
+
FAVS[id] = { id: id, _cat: cat, library_name: lib, savedAt: Date.now() };
|
| 769 |
+
toast('⭐ 已加入收藏夾!');
|
| 770 |
+
}
|
| 771 |
+
try { localStorage.setItem('hf_favs', JSON.stringify(FAVS)); } catch(e) {}
|
| 772 |
+
updateFavCount();
|
| 773 |
+
if (SHOWING_FAVS) renderFavs();
|
| 774 |
+
else fetchAndRender();
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
function toggleFavsView() {
|
| 778 |
+
SHOWING_FAVS = !SHOWING_FAVS;
|
| 779 |
+
var btn = document.getElementById('btn-favs');
|
| 780 |
+
if (SHOWING_FAVS) {
|
| 781 |
+
if (btn) btn.classList.add('ring-2', 'ring-amber-500');
|
| 782 |
+
renderFavs();
|
| 783 |
+
} else {
|
| 784 |
+
if (btn) btn.classList.remove('ring-2', 'ring-amber-500');
|
| 785 |
+
fetchAndRender();
|
| 786 |
+
}
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
function clearFavs() {
|
| 790 |
+
if (!confirm('確定要清空所有收藏嗎?')) return;
|
| 791 |
+
FAVS = {};
|
| 792 |
+
try { localStorage.removeItem('hf_favs'); } catch(e) {}
|
| 793 |
+
updateFavCount();
|
| 794 |
+
renderFavs();
|
| 795 |
+
toast('已清空所有收藏!');
|
| 796 |
+
}
|
| 797 |
+
|
| 798 |
+
function renderFavs() {
|
| 799 |
+
var items = Object.values(FAVS);
|
| 800 |
+
var rc = document.getElementById('result-count');
|
| 801 |
+
if (rc) {
|
| 802 |
+
rc.innerHTML = '收藏庫 (' + items.length + ') ' + (items.length ? '<button onclick="clearFavs()" class="ml-3 px-2 py-0.5 text-xs bg-red-500/20 text-red-300 border border-red-500/30 rounded hover:bg-red-500 hover:text-white transition">🗑️ 清空收藏</button>' : '');
|
| 803 |
+
rc.style.display = 'inline';
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
if (!items.length) {
|
| 807 |
+
document.getElementById('results-grid').style.display = 'none';
|
| 808 |
+
document.getElementById('empty-state').style.display = 'block';
|
| 809 |
+
document.getElementById('empty-title').textContent = '收藏庫是空的';
|
| 810 |
+
document.getElementById('empty-desc').textContent = '點擊卡片右上角的 ⭐ 即可收藏';
|
| 811 |
+
setStatus('Favorites empty', false);
|
| 812 |
+
return;
|
| 813 |
+
}
|
| 814 |
+
setStatus('顯示收藏庫中 (' + items.length + ' 筆)', false);
|
| 815 |
+
renderCards(items);
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
function copyPythonCode(e, id, cat, lib) {
|
| 819 |
+
if (e && e.stopPropagation) e.stopPropagation();
|
| 820 |
+
var code = '';
|
| 821 |
+
if (cat === 'dataset') {
|
| 822 |
+
code = 'from datasets import load_dataset\n\ndataset = load_dataset("' + id + '")';
|
| 823 |
+
} else if (cat === 'space') {
|
| 824 |
+
code = 'import gradio as gr\n\ndemo = gr.load("' + id + '", src="spaces")\ndemo.launch()';
|
| 825 |
+
} else {
|
| 826 |
+
if (lib === 'diffusers') {
|
| 827 |
+
code = 'from diffusers import DiffusionPipeline\nimport torch\n\npipeline = DiffusionPipeline.from_pretrained("' + id + '")\n# pipeline.to("cuda")';
|
| 828 |
+
} else {
|
| 829 |
+
code = 'from transformers import AutoModelForCausalLM, AutoTokenizer\n\ntokenizer = AutoTokenizer.from_pretrained("' + id + '")\nmodel = AutoModelForCausalLM.from_pretrained("' + id + '")';
|
| 830 |
+
}
|
| 831 |
+
}
|
| 832 |
+
navigator.clipboard.writeText(code).then(function() {
|
| 833 |
+
toast('📋 已複製 Python 載入程式碼!');
|
| 834 |
+
}).catch(function() {
|
| 835 |
+
toast('複製失敗', true);
|
| 836 |
+
});
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
// Init
|
| 840 |
try {
|
| 841 |
var savedSize = localStorage.getItem('text_size');
|