diff --git a/common/api.js b/common/api.js index def6c2c..d82a57a 100644 --- a/common/api.js +++ b/common/api.js @@ -1,5 +1,5 @@ var test_api = 'https://api-test.global-interaction.com/'; -var local_api = 'http://localhost:13000/'; +var local_api = 'http://127.0.0.1:13000/'; var default_api = 'https://api.global-interaction.com/'; (function () { @@ -115,14 +115,34 @@ var default_api = 'https://api.global-interaction.com/'; if (shouldPersist()) window.localStorage.removeItem(APP_CODE_KEY); } + function errorMessageForResponse(response, payload) { + if (response.status === 409) return 'Duplicate request.'; + return payload.message || response.statusText || 'request_failed'; + } + + function notifyHTTPError(response, message) { + if (response.status !== 409 || !message) return; + if (window.HyAppToast && window.HyAppToast.show) { + window.HyAppToast.show(message); + return; + } + window.dispatchEvent( + new CustomEvent('hyapp:toast', { + detail: { message: message }, + }) + ); + } + function parseResponse(response) { return response.text().then(function (text) { var payload = text ? JSON.parse(text) : {}; if (!response.ok) { - var httpError = new Error( - payload.message || response.statusText || 'request_failed' - ); + var message = errorMessageForResponse(response, payload); + notifyHTTPError(response, message); + var httpError = new Error(message); httpError.status = response.status; + httpError.code = payload.code; + httpError.request_id = payload.request_id; httpError.payload = payload; throw httpError; } diff --git a/common/i18n.js b/common/i18n.js index d79ae51..b6d88f0 100644 --- a/common/i18n.js +++ b/common/i18n.js @@ -2,6 +2,11 @@ var STORAGE_KEY = 'hyapp_h5_lang'; var DEFAULT_LANG = 'en'; var SUPPORTED = ['en', 'ar', 'tr', 'es']; + var scriptURL = + document.currentScript && document.currentScript.src + ? document.currentScript.src + : '../common/i18n.js'; + var localeBaseURL = new URL('locales/', scriptURL).toString(); var messages = {}; var currentLang = ''; @@ -33,7 +38,7 @@ function load(lang) { var normalized = normalizeLang(lang) || DEFAULT_LANG; return window - .fetch('../common/locales/' + normalized + '.json', { + .fetch(localeBaseURL + normalized + '.json', { cache: 'no-store', }) .then(function (response) { diff --git a/common/locales/ar.json b/common/locales/ar.json index f17272e..84377dd 100644 --- a/common/locales/ar.json +++ b/common/locales/ar.json @@ -12,11 +12,19 @@ "host_center.search": "بحث", "host_center.agency": "الوكالة", "host_center.apply": "تقديم", + "host_center.agency_list": "قائمة الوكالات", "host_center.search_required": "أدخل رقم الوكالة.", "host_center.searching": "جار البحث...", - "host_center.no_agency": "لم يتم العثور على وكالة في منطقتك.", + "host_center.loading_agencies": "جار تحميل الوكالات...", + "host_center.no_agency": "لم يتم العثور على وكالة في بلدك.", "host_center.search_failed": "فشل البحث. حاول لاحقا.", "host_center.apply_failed": "فشل إرسال الطلب. حاول لاحقا.", "host_center.apply_success": "تم إرسال الطلب.", - "host_center.applying": "جار الإرسال..." + "host_center.applying": "جار الإرسال...", + "host_center.host_count_one": "مضيف واحد", + "host_center.host_count_many": "{count} مضيفين", + "host_center.join": "انضم", + "host_center.cancel": "إلغاء", + "host_center.join_confirm_title": "انضم إلى وكالة", + "host_center.join_confirm_message": "هل أنت متأكد أنك تريد الانضمام إلى {agency}؟" } diff --git a/common/locales/en.json b/common/locales/en.json index e2bdf96..a3a6e80 100644 --- a/common/locales/en.json +++ b/common/locales/en.json @@ -12,11 +12,19 @@ "host_center.search": "Search", "host_center.agency": "Agency", "host_center.apply": "Apply", + "host_center.agency_list": "Agency list", "host_center.search_required": "Enter an agency ID.", "host_center.searching": "Searching...", - "host_center.no_agency": "No agency found in your region.", + "host_center.loading_agencies": "Loading agencies...", + "host_center.no_agency": "No agency found in your country.", "host_center.search_failed": "Search failed. Try again later.", "host_center.apply_failed": "Application failed. Try again later.", "host_center.apply_success": "Application submitted.", - "host_center.applying": "Submitting..." + "host_center.applying": "Submitting...", + "host_center.host_count_one": "1 host", + "host_center.host_count_many": "{count} hosts", + "host_center.join": "Join", + "host_center.cancel": "Cancel", + "host_center.join_confirm_title": "Join Agency", + "host_center.join_confirm_message": "Are you sure you want to join {agency}?" } diff --git a/common/locales/es.json b/common/locales/es.json index 72f2575..98ce8b7 100644 --- a/common/locales/es.json +++ b/common/locales/es.json @@ -12,11 +12,19 @@ "host_center.search": "Buscar", "host_center.agency": "Agencia", "host_center.apply": "Solicitar", + "host_center.agency_list": "Lista de agencias", "host_center.search_required": "Ingresa un ID de agencia.", "host_center.searching": "Buscando...", - "host_center.no_agency": "No se encontró ninguna agencia en tu región.", + "host_center.loading_agencies": "Cargando agencias...", + "host_center.no_agency": "No se encontró ninguna agencia en tu país.", "host_center.search_failed": "La búsqueda falló. Inténtalo más tarde.", "host_center.apply_failed": "La solicitud falló. Inténtalo más tarde.", "host_center.apply_success": "Solicitud enviada.", - "host_center.applying": "Enviando..." + "host_center.applying": "Enviando...", + "host_center.host_count_one": "1 host", + "host_center.host_count_many": "{count} hosts", + "host_center.join": "Unirse", + "host_center.cancel": "Cancelar", + "host_center.join_confirm_title": "Unirse a una agencia", + "host_center.join_confirm_message": "¿Seguro que quieres unirte a {agency}?" } diff --git a/common/locales/id.json b/common/locales/id.json index d11dfb3..a76b998 100644 --- a/common/locales/id.json +++ b/common/locales/id.json @@ -12,11 +12,19 @@ "host_center.search": "Cari", "host_center.agency": "Agency", "host_center.apply": "Ajukan", + "host_center.agency_list": "Daftar agency", "host_center.search_required": "Masukkan ID agency.", "host_center.searching": "Mencari...", - "host_center.no_agency": "Agency tidak ditemukan di wilayah Anda.", + "host_center.loading_agencies": "Memuat agency...", + "host_center.no_agency": "Agency tidak ditemukan di negara Anda.", "host_center.search_failed": "Pencarian gagal. Coba lagi nanti.", "host_center.apply_failed": "Pengajuan gagal. Coba lagi nanti.", "host_center.apply_success": "Pengajuan terkirim.", - "host_center.applying": "Mengirim..." + "host_center.applying": "Mengirim...", + "host_center.host_count_one": "1 host", + "host_center.host_count_many": "{count} host", + "host_center.join": "Gabung", + "host_center.cancel": "Batal", + "host_center.join_confirm_title": "Gabung Agency", + "host_center.join_confirm_message": "Apakah Anda yakin ingin bergabung dengan {agency}?" } diff --git a/common/locales/tr.json b/common/locales/tr.json index 51684d4..c672af2 100644 --- a/common/locales/tr.json +++ b/common/locales/tr.json @@ -12,11 +12,19 @@ "host_center.search": "Ara", "host_center.agency": "Ajans", "host_center.apply": "Başvur", + "host_center.agency_list": "Ajans listesi", "host_center.search_required": "Ajans ID girin.", "host_center.searching": "Aranıyor...", - "host_center.no_agency": "Bölgenizde ajans bulunamadı.", + "host_center.loading_agencies": "Ajanslar yükleniyor...", + "host_center.no_agency": "Ülkenizde ajans bulunamadı.", "host_center.search_failed": "Arama başarısız. Daha sonra deneyin.", "host_center.apply_failed": "Başvuru başarısız. Daha sonra deneyin.", "host_center.apply_success": "Başvuru gönderildi.", - "host_center.applying": "Gönderiliyor..." + "host_center.applying": "Gönderiliyor...", + "host_center.host_count_one": "1 host", + "host_center.host_count_many": "{count} host", + "host_center.join": "Katıl", + "host_center.cancel": "İptal", + "host_center.join_confirm_title": "Ajansa Katıl", + "host_center.join_confirm_message": "{agency} için katılmak istediğinizden emin misiniz?" } diff --git a/common/locales/zh.json b/common/locales/zh.json index 4441b70..5c35ec7 100644 --- a/common/locales/zh.json +++ b/common/locales/zh.json @@ -12,11 +12,19 @@ "host_center.search": "搜索", "host_center.agency": "公会", "host_center.apply": "申请", + "host_center.agency_list": "公会列表", "host_center.search_required": "请输入公会 ID。", "host_center.searching": "搜索中...", - "host_center.no_agency": "未找到同区域公会。", + "host_center.loading_agencies": "公会加载中...", + "host_center.no_agency": "未找到同国家公会。", "host_center.search_failed": "搜索失败,请稍后重试。", "host_center.apply_failed": "申请失败,请稍后重试。", "host_center.apply_success": "申请已提交。", - "host_center.applying": "提交中..." + "host_center.applying": "提交中...", + "host_center.host_count_one": "1 位主播", + "host_center.host_count_many": "{count} 位主播", + "host_center.join": "加入", + "host_center.cancel": "取消", + "host_center.join_confirm_title": "加入公会", + "host_center.join_confirm_message": "确定要加入 {agency} 吗?" } diff --git a/common/params.js b/common/params.js index a154fae..7a9b35c 100644 --- a/common/params.js +++ b/common/params.js @@ -25,9 +25,18 @@ return ''; } + function normalizeToken(value) { + var token = String(value || '').trim(); + if (!token) return ''; + var match = token.match( + /[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/ + ); + return match ? match[0] : token; + } + function parse() { var params = query(); - var token = first(params, TOKEN_KEYS); + var token = normalizeToken(first(params, TOKEN_KEYS)); var appCode = first(params, APP_CODE_KEYS) || window.localStorage.getItem('hyapp_app_code') || diff --git a/common/theme.css b/common/theme.css index 7953c5a..9277e44 100644 --- a/common/theme.css +++ b/common/theme.css @@ -13,8 +13,10 @@ --hy-theme-success: #31c6a8; --hy-theme-danger: #d95d72; --hy-theme-shadow: 0 10px 24px rgba(132, 90, 212, 0.075); - --hy-theme-button: #c5a6f6; - --hy-theme-button-shadow: 0 8px 18px rgba(132, 90, 212, 0.11); + --hy-theme-button: #7d57c7; + --hy-theme-button-disabled: #c5a6f6; + --hy-theme-button-shadow: 0 8px 18px rgba(125, 87, 199, 0.18); + --hy-theme-button-disabled-shadow: none; --hy-theme-hero: linear-gradient( 151deg, #f0e6ff 0%, diff --git a/common/toast.js b/common/toast.js new file mode 100644 index 0000000..7a895e7 --- /dev/null +++ b/common/toast.js @@ -0,0 +1,87 @@ +(function () { + var STYLE_ID = 'hy-global-toast-style'; + var TOAST_ID = 'hy-global-toast'; + var timer = 0; + + function ensureStyle() { + if (document.getElementById(STYLE_ID)) return; + var style = document.createElement('style'); + style.id = STYLE_ID; + style.textContent = [ + '.hy-global-toast{', + 'position:fixed;', + 'left:50%;', + 'top:max(84px,calc(env(safe-area-inset-top) + 24px));', + 'z-index:10000;', + 'max-width:min(320px,calc(100vw - 48px));', + 'padding:10px 14px;', + 'border-radius:8px;', + 'background:rgba(0,0,0,.82);', + 'color:#fff;', + 'font:800 14px/1.35 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;', + 'text-align:center;', + 'box-shadow:0 10px 28px rgba(0,0,0,.22);', + 'opacity:0;', + 'pointer-events:none;', + 'transform:translate(-50%,-8px);', + 'transition:opacity .18s ease,transform .18s ease;', + '}', + '.hy-global-toast.is-visible{', + 'opacity:1;', + 'transform:translate(-50%,0);', + '}', + ].join(''); + document.head.appendChild(style); + } + + function ensureToast() { + var node = document.getElementById(TOAST_ID); + if (node) return node; + ensureStyle(); + node = document.createElement('div'); + node.id = TOAST_ID; + node.className = 'hy-global-toast'; + node.setAttribute('role', 'status'); + node.setAttribute('aria-live', 'polite'); + document.body.appendChild(node); + return node; + } + + function hide() { + var node = document.getElementById(TOAST_ID); + if (node) node.classList.remove('is-visible'); + } + + function show(message, options) { + var text = String(message || '').trim(); + if (!text) return; + if (!document.body) { + document.addEventListener( + 'DOMContentLoaded', + function () { + show(text, options); + }, + { once: true } + ); + return; + } + var node = ensureToast(); + var duration = Number((options && options.duration) || 1800); + node.textContent = text; + window.requestAnimationFrame(function () { + node.classList.add('is-visible'); + }); + window.clearTimeout(timer); + timer = window.setTimeout(hide, duration); + } + + window.HyAppToast = { + show: show, + hide: hide, + }; + + window.addEventListener('hyapp:toast', function (event) { + var detail = event.detail || {}; + show(detail.message || detail.text, detail); + }); +})(); diff --git a/gonghui/agency.html b/gonghui/agency.html deleted file mode 100644 index e69de29..0000000 diff --git a/gonghui/bd.html b/gonghui/bd.html deleted file mode 100644 index e69de29..0000000 diff --git a/gonghui/bdleader.html b/gonghui/bdleader.html deleted file mode 100644 index e69de29..0000000 diff --git a/gonghui/coinsaller.html b/gonghui/coinsaller.html deleted file mode 100644 index e69de29..0000000 diff --git a/gonghui/host-center/script.js b/gonghui/host-center/script.js deleted file mode 100644 index 1498acf..0000000 --- a/gonghui/host-center/script.js +++ /dev/null @@ -1,180 +0,0 @@ -(function () { - var selectedAgency = null; - - function $(id) { - return document.getElementById(id); - } - - function t(key, fallback) { - return window.HyAppI18n && window.HyAppI18n.t - ? window.HyAppI18n.t(key, fallback) - : fallback || key; - } - - function setStatus(key, kind) { - var node = $('joinAgencyStatus'); - if (!node) return; - if (!key) { - node.hidden = true; - node.textContent = ''; - node.className = 'join-agency-status'; - return; - } - node.hidden = false; - node.className = 'join-agency-status' + (kind ? ' is-' + kind : ''); - node.textContent = t(key); - } - - function setSearching(searching) { - var input = $('agencySearchInput'); - var button = $('agencySearchButton'); - if (input) input.disabled = searching; - if (button) { - button.disabled = searching; - button.textContent = searching - ? t('host_center.searching', 'Searching...') - : t('host_center.search', 'Search'); - } - } - - function setApplying(applying) { - var button = $('joinAgencyApplyButton'); - if (!button) return; - button.disabled = applying || !selectedAgency; - button.textContent = applying - ? t('host_center.applying', 'Submitting...') - : t('host_center.apply', 'Apply'); - } - - function agencyID(agency) { - return String((agency && (agency.agency_id || agency.agencyId)) || ''); - } - - function agencyName(agency) { - return String((agency && agency.name) || ''); - } - - function renderAgency(agency) { - selectedAgency = agency || null; - var result = $('joinAgencyResult'); - if (!result) return; - if (!selectedAgency) { - result.hidden = true; - setApplying(false); - return; - } - var name = - agencyName(selectedAgency) || t('host_center.agency', 'Agency'); - result.hidden = false; - $('agencyName').textContent = name; - $('agencyAccount').textContent = 'ID: ' + agencyID(selectedAgency); - $('agencyInitial').textContent = - name.trim().charAt(0).toUpperCase() || 'A'; - setApplying(false); - } - - function searchAgency(event) { - if (event) event.preventDefault(); - if (!window.HyAppAPI || !window.HyAppAPI.host) return; - var input = $('agencySearchInput'); - var shortID = input ? input.value.trim() : ''; - selectedAgency = null; - renderAgency(null); - if (!shortID) { - setStatus('host_center.search_required', 'error'); - return; - } - setStatus('host_center.searching'); - setSearching(true); - window.HyAppAPI.host - .searchAgencies(shortID, 20) - .then(function (data) { - var items = (data && (data.items || data.agencies)) || []; - if (!items.length) { - setStatus('host_center.no_agency', 'error'); - return; - } - setStatus(''); - renderAgency(items[0]); - }) - .catch(function () { - setStatus('host_center.search_failed', 'error'); - }) - .finally(function () { - setSearching(false); - }); - } - - function applyAgency() { - if (!selectedAgency || !window.HyAppAPI || !window.HyAppAPI.host) - return; - setStatus('host_center.applying'); - setApplying(true); - window.HyAppAPI.host - .applyToAgency({ - agency_id: agencyID(selectedAgency), - command_id: - 'host_apply_' + - Date.now() + - '_' + - Math.random().toString(16).slice(2), - }) - .then(function () { - setStatus('host_center.apply_success', 'success'); - }) - .catch(function () { - setStatus('host_center.apply_failed', 'error'); - }) - .finally(function () { - setApplying(false); - }); - } - - function renderUser(current) { - var user = current && current.user; - var profile = user && (user.profile || user.user || user); - if (!profile) return; - var name = profile.username || profile.name || profile.nickname || ''; - var uid = - profile.display_user_id || - profile.displayUserId || - profile.user_id || - profile.userId || - ''; - if (name && $('profileName')) { - $('profileName').removeAttribute('data-i18n'); - $('profileName').textContent = name; - } - if (uid && $('profileUID')) { - $('profileUID').removeAttribute('data-i18n'); - $('profileUID').textContent = 'UID: ' + uid; - } - } - - function init() { - if (window.HyAppParams) { - window.HyAppParams.parse(); - window.HyAppParams.loadUser() - .then(renderUser) - .catch(function () {}); - } - var form = $('joinAgencyForm'); - if (form) form.addEventListener('submit', searchAgency); - var applyButton = $('joinAgencyApplyButton'); - if (applyButton) applyButton.addEventListener('click', applyAgency); - var backButton = $('backButton'); - if (backButton) { - backButton.addEventListener('click', function () { - if (window.HyAppBridge) window.HyAppBridge.back(); - }); - } - setApplying(false); - } - - window.addEventListener('hyapp:i18n-ready', function () { - setSearching(false); - setApplying(false); - }); - - document.addEventListener('DOMContentLoaded', init); -})(); diff --git a/gonghui/host.html b/gonghui/host.html deleted file mode 100644 index e69de29..0000000 diff --git a/gonghui/host-center/index.html b/gonghui/unhost-center/index.html similarity index 67% rename from gonghui/host-center/index.html rename to gonghui/unhost-center/index.html index 313289f..072ca45 100644 --- a/gonghui/host-center/index.html +++ b/gonghui/unhost-center/index.html @@ -7,7 +7,7 @@ content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />