;(() => { // 创建样式 const style = document.createElement('style') style.id = 'genspark-badge' style.textContent = ` .genspark-badge-button { position: fixed; bottom: 20px; right: 20px; background-color: #333; color: white; border: none; border-radius: 4px; padding: 8px 12px; font-size: 12px; cursor: pointer; z-index: 9999; display: flex; align-items: center; gap: 6px; } .genspark-modal { display: none; position: fixed; bottom: 80px; right: 20px; z-index: 10000; justify-content: end; } .genspark-modal-content { background-color: white; border-radius: 8px; max-width: 450px; width: 100%; box-sizing: border-box; padding: 20px; position: relative; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); font-size: 14px; } @media (max-width: 768px) { .genspark-modal-content { max-width: 90%; } } .genspark-close { position: absolute; top: 10px; right: 10px; font-size: 20px; cursor: pointer; background: none; border: none; } .genspark-title { margin-bottom: 8px; font-weight: normal; display: inline; font-size: 14px; } .genspark-report { color: #909499; text-decoration: underline; cursor: pointer; margin-bottom: 14px; display: inline; } .genspark-info { margin: 25px 0; color: #333; font-size: 14px; } .genspark-buttons { display: flex; gap: 10px; } .genspark-remove-btn { background-color: #f5f5f5; border: 1px solid #ddd; color: #333; padding: 4px 14px; border-radius: 8px; cursor: pointer; flex: 1; font-size: 14px; box-sizing: border-box; } .genspark-go-btn { background-color: #222; border: none; color: white; padding: 4px 14px; border-radius: 8px; cursor: pointer; flex: 1; font-size: 14px; box-sizing: border-box; } ` document.head.appendChild(style) // 获取当前语言 const getCurrentLocale = () => { // 优先检查全局变量 window.__genspark_locale if (window.__genspark_locale) { return window.__genspark_locale } // 回退到浏览器语言 const browserLang = navigator.language || navigator.userLanguage // 简单映射到我们支持的语言 const supportedLocales = [ 'en-US', 'zh-CN', 'zh-TW', 'ja-JP', 'ko-KR', 'fr-FR', 'de-DE', 'es-ES', 'it-IT', 'pt-BR', 'ru-RU', 'hi-IN', 'ar-EG', ] // 查找匹配的语言 const matchedLocale = supportedLocales.find(locale => browserLang.toLowerCase().startsWith(locale.toLowerCase().split('-')[0]) ) return matchedLocale || 'en-US' // 默认英语 } // 获取本地化文本 const getLocalizedText = () => { const locale = getCurrentLocale() const translations = { 'en-US': { buttonText: 'Made with Genspark', titleText: 'This page was created by users with AI.', reportText: 'Report inappropriate content.', infoText: 'Page owner with Plus Plan can remove badge.', removeButtonText: 'Remove Badge', goButtonText: 'Go to Genspark', }, 'zh-CN': { buttonText: '由 Genspark 制作', titleText: '此页面由用户使用 AI 创建。', reportText: '举报不当内容。', infoText: 'Plus 计划的页面所有者可以移除徽章。', removeButtonText: '移除徽章', goButtonText: '前往 Genspark', }, 'zh-TW': { buttonText: '由 Genspark 製作', titleText: '此頁面由用戶使用 AI 創建。', reportText: '舉報不當內容。', infoText: 'Plus 計劃的頁面所有者可以移除徽章。', removeButtonText: '移除徽章', goButtonText: '前往 Genspark', }, 'ja-JP': { buttonText: 'Genspark で作成', titleText: 'このページはユーザーがAIで作成しました。', reportText: '不適切なコンテンツを報告する。', infoText: 'Plus プランのページ所有者はバッジを削除できます。', removeButtonText: 'バッジを削除', goButtonText: 'Genspark へ', }, 'ko-KR': { buttonText: 'Genspark로 제작됨', titleText: '이 페이지는 사용자가 AI로 만들었습니다.', reportText: '부적절한 콘텐츠 신고.', infoText: 'Plus 플랜 페이지 소유자는 배지를 제거할 수 있습니다.', removeButtonText: '배지 제거', goButtonText: 'Genspark로 이동', }, 'fr-FR': { buttonText: 'Créé avec Genspark', titleText: 'Cette page a été créée par des utilisateurs avec IA.', reportText: 'Signaler un contenu inapproprié.', infoText: 'Le propriétaire de la page avec le plan Plus peut supprimer le badge.', removeButtonText: 'Supprimer le badge', goButtonText: 'Aller à Genspark', }, 'de-DE': { buttonText: 'Erstellt mit Genspark', titleText: 'Diese Seite wurde von Benutzern mit KI erstellt.', reportText: 'Unangemessene Inhalte melden.', infoText: 'Seitenbesitzer mit Plus-Plan können das Abzeichen entfernen.', removeButtonText: 'Abzeichen entfernen', goButtonText: 'Zu Genspark', }, 'es-ES': { buttonText: 'Hecho con Genspark', titleText: 'Esta página fue creada por usuarios con IA.', reportText: 'Reportar contenido inapropiado.', infoText: 'El propietario de la página con Plan Plus puede eliminar la insignia.', removeButtonText: 'Eliminar insignia', goButtonText: 'Ir a Genspark', }, 'it-IT': { buttonText: 'Creato con Genspark', titleText: "Questa pagina è stata creata dagli utenti con l'IA.", reportText: 'Segnala contenuti inappropriati.', infoText: 'Il proprietario della pagina con Piano Plus può rimuovere il badge.', removeButtonText: 'Rimuovi badge', goButtonText: 'Vai a Genspark', }, 'pt-BR': { buttonText: 'Feito com Genspark', titleText: 'Esta página foi criada por usuários com IA.', reportText: 'Reportar conteúdo inadequado.', infoText: 'O proprietário da página com Plano Plus pode remover o distintivo.', removeButtonText: 'Remover distintivo', goButtonText: 'Ir para Genspark', }, 'ru-RU': { buttonText: 'Сделано с Genspark', titleText: 'Эта страница создана пользователями с помощью ИИ.', reportText: 'Сообщить о неприемлемом содержании.', infoText: 'Владелец страницы с тарифом Plus может удалить значок.', removeButtonText: 'Удалить значок', goButtonText: 'Перейти к Genspark', }, 'hi-IN': { buttonText: 'Genspark के साथ बनाया गया', titleText: 'यह पेज उपयोगकर्ताओं द्वारा AI के साथ बनाया गया था।', reportText: 'अनुचित सामग्री की रिपोर्ट करें।', infoText: 'प्लस प्लान वाले पेज के मालिक बैज हटा सकते हैं।', removeButtonText: 'बैज हटाएं', goButtonText: 'Genspark पर जाएं', }, 'ar-EG': { buttonText: 'صنع بواسطة Genspark', titleText: 'تم إنشاء هذه الصفحة بواسطة المستخدمين مع الذكاء الاصطناعي.', reportText: 'الإبلاغ عن محتوى غير لائق.', infoText: 'يمكن لمالك الصفحة مع خطة بلس إزالة الشارة.', removeButtonText: 'إزالة الشارة', goButtonText: 'الذهاب إلى Genspark', }, } return translations[locale] || translations['en-US'] } const localizedText = getLocalizedText() // 创建徽章按钮 const badgeButton = document.createElement('button') badgeButton.className = 'genspark-badge-button' badgeButton.innerHTML = ` ${localizedText.buttonText}` // 检查是否在iframe中以及父窗口地址 const isInIframe = window.self !== window.top let shouldShowBadge = true if (isInIframe) { try { // 尝试获取父窗口的URL const parentUrl = window.parent.location.href // 只有当父窗口URL包含html_badge_test.html时才显示 shouldShowBadge = parentUrl.includes('html_badge_test.html') } catch (e) { // 如果无法访问父窗口URL(跨域限制),默认不显示 shouldShowBadge = false } } // 只有当shouldShowBadge为true时才添加徽章按钮 if (shouldShowBadge) { document.body.appendChild(badgeButton) } // 创建模态框 const modal = document.createElement('div') modal.className = 'genspark-modal' modal.innerHTML = `
` // 只有当shouldShowBadge为true时才添加模态框 if (shouldShowBadge) { document.body.appendChild(modal) // 定义一个全局计时器变量 let hideTimeout // 事件监听 badgeButton.addEventListener('click', () => { modal.style.display = 'flex' }) // 鼠标悬停时也显示badge badgeButton.addEventListener('mouseenter', () => { modal.style.display = 'flex' clearTimeout(hideTimeout) // 清除已有的计时器 }) // 鼠标离开badgeButton时,延迟1秒关闭modal badgeButton.addEventListener('mouseleave', () => { hideTimeout = setTimeout(() => { modal.style.display = 'none' }, 1000) }) // 鼠标进入modal时,清除计时器 modal.addEventListener('mouseenter', () => { clearTimeout(hideTimeout) }) // 鼠标离开modal时,延迟1秒关闭modal modal.addEventListener('mouseleave', () => { hideTimeout = setTimeout(() => { modal.style.display = 'none' }, 1000) }) const closeButton = modal.querySelector('.genspark-close') closeButton.addEventListener('click', () => { modal.style.display = 'none' }) // 点击模态框外部关闭 document.addEventListener('click', e => { if ( modal.style.display === 'block' && !modal.contains(e.target) && e.target !== badgeButton ) { modal.style.display = 'none' } }) // 添加按钮功能 const removeButton = modal.querySelector('.genspark-remove-btn') removeButton.addEventListener('click', () => { // 检测是否在iframe中 if (window.self !== window.top) { // 在iframe中,使用postMessage发送token消息给父窗口 window.parent.postMessage( { type: 'html_badge_remove_badge', payload: { token: window.__genspark_token, }, }, '*' ) } else { // 不在iframe中,使用原来的逻辑 if (window.__genspark_remove_badge_link) { window.location.href = window.__genspark_remove_badge_link } } console.log('Remove badge clicked') }) const goButton = modal.querySelector('.genspark-go-btn') goButton.addEventListener('click', () => { // 这里可以添加跳转到Genspark的逻辑 window.open('https://www.genspark.ai', '_blank') }) } })()