Download store-controller.js from Althnayi/fc: direct link, hf CLI and curl.
- Browser
- Download file 11.2 kB
-
https://huggingface.co/spaces/Althnayi/fc/resolve/main/store-controller.js
- Command line
-
hf download hf://spaces/Althnayi/fc/store-controller.js
-
curl -L -o store-controller.js https://huggingface.co/spaces/Althnayi/fc/resolve/main/store-controller.js
11.2 kB
| /** | |
| * @fileoverview Store Exchange & Points Purchasing Controller | |
| * @module controllers/store-controller | |
| * @description وحدة التحكم في حاسبة استبدال النقاط التفاعلية وتنفيذ الشراء المباشر والخصم من المحفظة. | |
| */ | |
| (global => { | |
| 'use strict'; | |
| /** | |
| * تحديث وحساب مخرجات حاسبة شراء النقاط المباشرة | |
| * @returns {{ totalCostUSD: number, finalFbPoints: number, finalWaPoints: number }} | |
| */ | |
| const updateInteractiveCalculator = () => { | |
| const config = global.FritreeStoreConfig; | |
| if (!config) { | |
| console.warn("[Fritree Store Calculator] Config module not loaded yet."); | |
| return { totalCostUSD: 0, finalFbPoints: 0, finalWaPoints: 0 }; | |
| } | |
| const modeByUsdBtn = document.getElementById('e1kue4bxi8'); | |
| const isUsdMode = modeByUsdBtn ? modeByUsdBtn.classList.contains('vn5qn7dmpk') : true; | |
| let totalCostUSD = 0; | |
| let baseFbPoints = 0; | |
| let baseWaPoints = 0; | |
| if (isUsdMode) { | |
| const usdInp = document.getElementById('jkfrigkx79'); | |
| const usdSlider = document.getElementById('d59w7te1vj'); | |
| const splitSlider = document.getElementById('e89vbjxky3'); | |
| let usdVal = parseFloat(usdInp?.value) || 0.01; | |
| if (usdVal < 0.01) usdVal = 0.01; | |
| if (usdVal > 10000) usdVal = 10000; | |
| totalCostUSD = usdVal; | |
| if (usdSlider) usdSlider.value = Math.min(10000, usdVal); | |
| const fbPct = parseInt(splitSlider?.value || '50', 10); | |
| const waPct = 100 - fbPct; | |
| const fbUsd = (totalCostUSD * fbPct) / 100; | |
| const waUsd = (totalCostUSD * waPct) / 100; | |
| const lblFbPct = document.getElementById('qlifseac5g'); | |
| const lblFbUsd = document.getElementById('kh1jaojo84'); | |
| const lblWaPct = document.getElementById('vsgn1osooh'); | |
| const lblWaUsd = document.getElementById('fjb9lf7u6j'); | |
| if (lblFbPct) lblFbPct.textContent = fbPct.toLocaleString('en-US'); | |
| if (lblFbUsd) lblFbUsd.textContent = fbUsd.toFixed(2); | |
| if (lblWaPct) lblWaPct.textContent = waPct.toLocaleString('en-US'); | |
| if (lblWaUsd) lblWaUsd.textContent = waUsd.toFixed(2); | |
| baseFbPoints = Math.round(fbUsd * config.EXCHANGE_RATES.FB); | |
| baseWaPoints = Math.round(waUsd * config.EXCHANGE_RATES.WA); | |
| } else { | |
| const fbPtsInp = document.getElementById('ra4lnuh31g'); | |
| const waPtsInp = document.getElementById('obapd8lbcc'); | |
| baseFbPoints = Math.max(0, parseInt(fbPtsInp?.value, 10) || 0); | |
| baseWaPoints = Math.max(0, parseInt(waPtsInp?.value, 10) || 0); | |
| const fbCost = baseFbPoints / config.EXCHANGE_RATES.FB; | |
| const waCost = baseWaPoints / config.EXCHANGE_RATES.WA; | |
| totalCostUSD = fbCost + waCost; | |
| if (totalCostUSD > 10000) { | |
| totalCostUSD = 10000; | |
| } | |
| } | |
| const finalFbPoints = baseFbPoints; | |
| const finalWaPoints = baseWaPoints; | |
| const summaryCost = document.getElementById('xaaobpe28o'); | |
| const summaryBonusPct = document.getElementById('qtmqs3sswp'); | |
| const summaryFbTotal = document.getElementById('xl39vkuv1s'); | |
| const summaryWaTotal = document.getElementById('k7z19dhok1'); | |
| if (summaryCost) summaryCost.innerHTML = `<i class="fa-solid fa-dollar-sign"></i> <span>$${totalCostUSD.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</span>`; | |
| if (summaryBonusPct) { | |
| summaryBonusPct.innerHTML = `<i class="fa-solid fa-tag"></i> <span>تسعير مباشر</span>`; | |
| summaryBonusPct.style.color = "#64748b"; | |
| } | |
| if (summaryFbTotal) { | |
| summaryFbTotal.innerHTML = `<i class="fa-brands fa-facebook"></i> <span>${finalFbPoints.toLocaleString('en-US')} نقطة</span>`; | |
| } | |
| if (summaryWaTotal) { | |
| summaryWaTotal.innerHTML = `<i class="fa-brands fa-whatsapp"></i> <span>${finalWaPoints.toLocaleString('en-US')} نقطة</span>`; | |
| } | |
| return { | |
| totalCostUSD, | |
| finalFbPoints, | |
| finalWaPoints | |
| }; | |
| }; | |
| /** | |
| * تنفيذ شراء النقاط المخصصة من الحاسبة | |
| */ | |
| async function executeCustomCalculatorExchange() { | |
| const config = global.FritreeStoreConfig; | |
| const calcData = updateInteractiveCalculator(); | |
| const usdCost = calcData.totalCostUSD; | |
| if (usdCost < 0.01) { | |
| alert("تنبيه: الحد الأدنى للشراء هو $0.01 (1 سنت)!"); | |
| return; | |
| } | |
| if (usdCost > 10000.00) { | |
| alert("تنبيه: الحد الأقصى للشراء في المرة الواحدة هو $10,000.00 دولار!"); | |
| return; | |
| } | |
| const activeBalance = global.FritreeAppState ? global.FritreeAppState.getPoints() : 0.00; | |
| if (activeBalance < usdCost) { | |
| alert(`رصيد محفظتك المتاح ($${activeBalance.toFixed(2)}) مش كفاية لإتمام الشراء بتكلفة $${usdCost.toFixed(2)}.\n\nاشحن محفظتك الأول بالدولار.`); | |
| return; | |
| } | |
| const fbPts = calcData.finalFbPoints; | |
| const waPts = calcData.finalWaPoints; | |
| let promptMsg = `تأكيد الشراء المباشر للنقاط:\n\nالتكلفة الإجمالية: $${usdCost.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}\n`; | |
| if (fbPts > 0) promptMsg += `- فيسبوك: +${fbPts.toLocaleString('en-US')}\n`; | |
| if (waPts > 0) promptMsg += `- واتساب: +${waPts.toLocaleString('en-US')}\n`; | |
| promptMsg += `\nهل تريد تأكيد العملية والخصم من المحفظة؟`; | |
| if (confirm(promptMsg)) { | |
| const descDeduct = `شراء مباشر من المتجر عبر الحاسبة التفاعلية: -$${usdCost.toFixed(2)}`; | |
| const success = await global.FritreeAppState.deductPoints(usdCost, descDeduct); | |
| if (success) { | |
| const balanceAfterTx = activeBalance - usdCost; | |
| const computedSignature = await config.calculateExchangeSignature('combo', fbPts + waPts, usdCost, balanceAfterTx); | |
| if (global.FritreeStorage) { | |
| await global.FritreeStorage.set('last_exchange_receipt_sig', computedSignature); | |
| } | |
| if (fbPts > 0) { | |
| const descFb = `شحن نقاط فيسبوك من المتجر: +${fbPts.toLocaleString('en-US')}`; | |
| await global.FritreeAppState.addFbCards(fbPts, descFb); | |
| } | |
| if (waPts > 0) { | |
| const descWa = `شحن نقاط واتساب من المتجر: +${waPts.toLocaleString('en-US')}`; | |
| await global.FritreeAppState.addWaCards(waPts, descWa); | |
| } | |
| await global.FritreeAppState.saveAccountData(); | |
| if (global.FritreeShellLayout) global.FritreeShellLayout.updatePointsUI(); | |
| const successMsg = `تم الشراء بنجاح!\nتم شحن الأرصدة لمحفظتك الموحدة فوراً.`; | |
| alert(successMsg); | |
| if (typeof window.addLog === 'function') { | |
| window.addLog(successMsg, 'success'); | |
| } | |
| if (global.FritreeWallet && typeof global.FritreeWallet.renderLedgerTable === 'function') { | |
| await global.FritreeWallet.renderLedgerTable(); | |
| } | |
| } else { | |
| alert("خطأ: تعثر خصم الرصيد من المحفظة."); | |
| } | |
| } | |
| } | |
| /** | |
| * ربط أحداث حاسبة المتجر | |
| */ | |
| const bindCalculatorEvents = () => { | |
| const btnByUsd = document.getElementById('e1kue4bxi8'); | |
| const btnByPts = document.getElementById('oppazp520b'); | |
| const containerUsdMode = document.getElementById('ssaw6xzw1u'); | |
| const containerPtsMode = document.getElementById('ijac87awiy'); | |
| if (btnByUsd && btnByPts) { | |
| btnByUsd.addEventListener('click', () => { | |
| btnByUsd.classList.add('vn5qn7dmpk'); | |
| btnByPts.classList.remove('vn5qn7dmpk'); | |
| if (containerUsdMode) containerUsdMode.style.display = 'flex'; | |
| if (containerPtsMode) containerPtsMode.style.display = 'none'; | |
| updateInteractiveCalculator(); | |
| }); | |
| btnByPts.addEventListener('click', () => { | |
| btnByPts.classList.add('vn5qn7dmpk'); | |
| btnByUsd.classList.remove('vn5qn7dmpk'); | |
| if (containerPtsMode) containerPtsMode.style.display = 'flex'; | |
| if (containerUsdMode) containerUsdMode.style.display = 'none'; | |
| updateInteractiveCalculator(); | |
| }); | |
| } | |
| const usdInp = document.getElementById('jkfrigkx79'); | |
| const usdSlider = document.getElementById('d59w7te1vj'); | |
| const splitSlider = document.getElementById('e89vbjxky3'); | |
| if (usdInp) { | |
| usdInp.addEventListener('input', () => { | |
| let val = parseFloat(usdInp.value) || 0.01; | |
| if (val > 10000) val = 10000; | |
| usdInp.value = val; | |
| updateInteractiveCalculator(); | |
| }); | |
| usdInp.addEventListener('change', updateInteractiveCalculator); | |
| } | |
| if (usdSlider) { | |
| usdSlider.addEventListener('input', (e) => { | |
| if (usdInp) usdInp.value = parseFloat(e.target.value); | |
| updateInteractiveCalculator(); | |
| }); | |
| } | |
| if (splitSlider) { | |
| splitSlider.addEventListener('input', updateInteractiveCalculator); | |
| } | |
| const fbPtsInp = document.getElementById('ra4lnuh31g'); | |
| const waPtsInp = document.getElementById('obapd8lbcc'); | |
| if (fbPtsInp) fbPtsInp.addEventListener('input', updateInteractiveCalculator); | |
| if (waPtsInp) waPtsInp.addEventListener('input', updateInteractiveCalculator); | |
| const executeExchangeBtn = document.getElementById('fmkoglcexo'); | |
| if (executeExchangeBtn) { | |
| executeExchangeBtn.addEventListener('click', executeCustomCalculatorExchange); | |
| } | |
| }; | |
| /** | |
| * تصدير وحدة تحكم المتجر | |
| */ | |
| global.FritreeStoreCalculator = { | |
| updateCalculator: updateInteractiveCalculator, | |
| executeExchange: executeCustomCalculatorExchange, | |
| bindEvents: bindCalculatorEvents | |
| }; | |
| if (typeof document !== 'undefined') { | |
| bindCalculatorEvents(); | |
| } | |
| })(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this); |