@onairosofficial/onairos-capacitor 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +194 -10
- package/README.md +182 -25
- package/dist/onairos.capacitor.esm.js +1 -0
- package/dist/onairos.capacitor.esm.turbopack.js +1 -0
- package/onairos.d.ts +656 -0
- package/package.json +186 -38
- package/src/OnairosReconnectButton.jsx +272 -0
- package/src/RSA.jsx +57 -0
- package/src/assets/NewLogo.png +0 -0
- package/src/assets/OnairosNewLogo.png +0 -0
- package/src/assets/chatgpt-icon.png +0 -0
- package/src/assets/fire-horse.png +0 -0
- package/src/assets/fire-horse.transparent.png +0 -0
- package/src/assets/latest-firehorse.png +0 -0
- package/src/assets/perplexity.png +0 -0
- package/src/assets/persona.png +0 -0
- package/src/assets/persona1.png +0 -0
- package/src/assets/persona2.png +0 -0
- package/src/assets/persona3.png +0 -0
- package/src/assets/persona4.png +0 -0
- package/src/assets/persona5.png +0 -0
- package/src/capacitorConnectorCatalog.js +38 -0
- package/src/capacitorOAuthConfig.js +52 -0
- package/src/chatgptHostedImport/index.js +303 -0
- package/src/components/AuthButtons.jsx +48 -0
- package/src/components/ConnectChatGPTModal.jsx +666 -0
- package/src/components/ConnectClaudeModal.jsx +610 -0
- package/src/components/ConnectGeminiModal.jsx +639 -0
- package/src/components/ConnectGrokModal.jsx +701 -0
- package/src/components/ConnectPerplexityModal.jsx +726 -0
- package/src/components/DataExplainerScreen.jsx +349 -0
- package/src/components/DataRequest.js +885 -0
- package/src/components/DataRequest.jsx +1055 -0
- package/src/components/EmailAuth.js +1871 -0
- package/src/components/EmailAuth.jsx +2062 -0
- package/src/components/ExtensionInstallPrompt.jsx +142 -0
- package/src/components/GoogleButton.js +133 -0
- package/src/components/LLMConnectorManager.jsx +201 -0
- package/src/components/LoadingPage.jsx +19 -0
- package/src/components/LoadingScreen.jsx +81 -0
- package/src/components/LunarBirthdate.jsx +96 -0
- package/src/components/LunarLoadingPage.jsx +251 -0
- package/src/components/Notification.jsx +21 -0
- package/src/components/OnairosAppButton.jsx +85 -0
- package/src/components/OnairosSSO.jsx +645 -0
- package/src/components/OnairosTrigger.jsx +61 -0
- package/src/components/PerplexityLogo.jsx +43 -0
- package/src/components/PinSetup.js +200 -0
- package/src/components/PinSetup.jsx +228 -0
- package/src/components/SDK_PIN_INTEGRATION_REQUIRED_CHANGES.md +526 -0
- package/src/components/SdkErrorBoundary.jsx +36 -0
- package/src/components/SecuritySetup.js +81 -0
- package/src/components/SessionUserBar.jsx +83 -0
- package/src/components/SignUp.js +123 -0
- package/src/components/TestTelegramButton.js +53 -0
- package/src/components/TrainingComponent.jsx +200 -0
- package/src/components/TrainingScreen.jsx +897 -0
- package/src/components/UniversalOnboarding.js +306 -0
- package/src/components/UniversalOnboarding.jsx +4837 -0
- package/src/components/ValentineLoadingPage.jsx +502 -0
- package/src/components/ValentineModeSelector.jsx +162 -0
- package/src/components/WelcomeScreen.jsx +435 -0
- package/src/components/WrappedLoadingPage.jsx +205 -0
- package/src/components/connectors/ChatGPTConnector.js +348 -0
- package/src/components/connectors/ChatGPTConnector.jsx +348 -0
- package/src/components/connectors/ClaudeConnector.js +44 -0
- package/src/components/connectors/ClaudeConnector.jsx +44 -0
- package/src/components/connectors/GeminiConnector.js +170 -0
- package/src/components/connectors/GeminiConnector.jsx +170 -0
- package/src/components/connectors/GmailConnector.js +148 -0
- package/src/components/connectors/GmailConnector.jsx +148 -0
- package/src/components/connectors/GrokConnector.js +16 -0
- package/src/components/connectors/GrokConnector.jsx +16 -0
- package/src/components/connectors/HingeConnector.js +419 -0
- package/src/components/connectors/HingeConnector.jsx +419 -0
- package/src/components/connectors/InstagramDataConnector.js +726 -0
- package/src/components/connectors/InstagramDataConnector.jsx +726 -0
- package/src/components/connectors/LinkedInConnector.js +4 -0
- package/src/components/connectors/LinkedInConnector.jsx +296 -0
- package/src/components/connectors/PerplexityConnector.jsx +16 -0
- package/src/components/connectors/PinterestConnector.js +208 -0
- package/src/components/connectors/PinterestConnector.jsx +208 -0
- package/src/components/connectors/README.md +292 -0
- package/src/components/connectors/RedditConnector.js +229 -0
- package/src/components/connectors/RedditConnector.jsx +229 -0
- package/src/components/connectors/SephoraConnector.js +482 -0
- package/src/components/connectors/SephoraConnector.jsx +482 -0
- package/src/components/connectors/TikTokConnector.jsx +430 -0
- package/src/components/connectors/YoutubeConnector.js +361 -0
- package/src/components/connectors/YoutubeConnector.jsx +361 -0
- package/src/components/connectors/index.js +50 -0
- package/src/components/icons.jsx +46 -0
- package/src/components/icons.tsx +21 -0
- package/src/components/ui/PageLayout.jsx +1255 -0
- package/src/components/ui/PrimaryButton.jsx +162 -0
- package/src/components/ui/button.jsx +49 -0
- package/src/components/ui/card.jsx +61 -0
- package/src/components/ui/checkbox.jsx +33 -0
- package/src/components/ui/label.jsx +29 -0
- package/src/components/utils/UpdateConnections.js +45 -0
- package/src/components/utils/oauthHelper.js +97 -0
- package/src/config/api-config.js +138 -0
- package/src/deepLink.jsx +38 -0
- package/src/getPin.js +26 -0
- package/src/icons/Avatar.png +0 -0
- package/src/icons/Sentiment.png +0 -0
- package/src/icons/Trait.png +0 -0
- package/src/iframe/DataRequestPage.jsx +285 -0
- package/src/iframe/OnairosButtonIntegration.md +148 -0
- package/src/iframe/components/Box.jsx +56 -0
- package/src/iframe/components/IndividualConnection.jsx +88 -0
- package/src/iframe/dataRequestHandler.js +714 -0
- package/src/iframe/data_request_iframe.html +27 -0
- package/src/iframe/data_request_page.js +47 -0
- package/src/iframe/icons/Avatar.png +1 -0
- package/src/iframe/icons/Avatar2.png +1 -0
- package/src/iframe/icons/Sentiment.png +1 -0
- package/src/iframe/icons/Trait.png +1 -0
- package/src/iframe/icons/onairos_logo.png +0 -0
- package/src/iframe/utils/api.js +57 -0
- package/src/index.js +274 -0
- package/src/laravel/OnairosVue.vue +410 -0
- package/src/laravel/blade-helpers.js +320 -0
- package/src/laravel/vite-plugin.js +179 -0
- package/src/mobile/MobileDataRequestPage.jsx +233 -0
- package/src/mobile/components/MobileBox.jsx +71 -0
- package/src/mobile/components/MobileIndividualConnection.jsx +51 -0
- package/src/mobile/shims/browser-apis.js +78 -0
- package/src/mobile/shims/lucide-shim.js +85 -0
- package/src/newUI/EMAIL_VERIFICATION_API_SCHEMA.md +268 -0
- package/src/newUI/PlatformConnectorsStep.tsx +435 -0
- package/src/newUI/PrimaryButton.tsx +213 -0
- package/src/newUI/SignInStep.tsx +194 -0
- package/src/newUI/VerificationStep.tsx +133 -0
- package/src/newUI/WelcomeScreen.tsx +311 -0
- package/src/newUI/services/connectedAccountsService.js +129 -0
- package/src/onairos.capacitor.jsx +16 -0
- package/src/onairos.core.jsx +133 -0
- package/src/onairos.jsx +14 -0
- package/src/onairos.native.jsx +15 -0
- package/src/onairosButton.jsx +9000 -0
- package/src/overlay/CheckBox.jsx +114 -0
- package/src/overlay/IndividualConnection copy.js +86 -0
- package/src/overlay/IndividualConnection.js +191 -0
- package/src/overlay/IndividualConnectionNew.jsx +157 -0
- package/src/overlay/box.js +84 -0
- package/src/overlay/overlay.js +437 -0
- package/src/styles/onairos-scoped-preflight.css +97 -0
- package/src/styles/sdkCssRegistry.js +20 -0
- package/src/styles/styleLoaderInsertShadow.js +69 -0
- package/src/styles/tailwind.capacitor.css +395 -0
- package/src/styles/tailwind.css +395 -0
- package/src/theme/colors.js +40 -0
- package/src/utils/apiKeyValidation.js +341 -0
- package/src/utils/apiResponseLogger.js +316 -0
- package/src/utils/authHeaders.js +275 -0
- package/src/utils/biometrics.js +26 -0
- package/src/utils/bookmarkletUtils.js +28 -0
- package/src/utils/capacitorDetection.js +278 -0
- package/src/utils/capacitorLLMHelper.js +352 -0
- package/src/utils/capacitorPlugins.js +366 -0
- package/src/utils/crossDomainSSO.js +587 -0
- package/src/utils/deepLinking.js +27 -0
- package/src/utils/devLogger.js +46 -0
- package/src/utils/extensionDetection.js +418 -0
- package/src/utils/extractMemory.js +277 -0
- package/src/utils/framerBrandingOverrides.js +40 -0
- package/src/utils/googleWebClientId.js +55 -0
- package/src/utils/overlayHandler.js +224 -0
- package/src/utils/platformDisconnect.js +309 -0
- package/src/utils/pollTrainingStatus.js +200 -0
- package/src/utils/rawMemoriesAccess.js +211 -0
- package/src/utils/resolveBackendAppId.js +47 -0
- package/src/utils/responseFormatter.js +140 -0
- package/src/utils/sdkDebugStorage.js +113 -0
- package/src/utils/sdkInitialization.js +645 -0
- package/src/utils/sessionManager.js +1258 -0
- package/src/utils/startBackgroundTraining.js +100 -0
- package/src/utils/userDataFormatter.js +222 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
/* eslint-disable no-script-url */
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import * as ReactDOM from 'react-dom';
|
|
4
|
+
import { getApiBaseUrl } from '../config/api-config.js';
|
|
5
|
+
import { getApiKey, getUserToken } from '../utils/authHeaders.js';
|
|
6
|
+
|
|
7
|
+
const GROK_BOOKMARKLET_HREF = [
|
|
8
|
+
"javascript:(async function(){try{",
|
|
9
|
+
"var host=(location.hostname||'').toLowerCase();",
|
|
10
|
+
"if(!(host==='grok.com'||host.endsWith('.grok.com')||host==='grok.x.ai'||host.endsWith('.grok.x.ai')||host==='x.com'||host.endsWith('.x.com'))){alert('Please open Grok first.');return;}",
|
|
11
|
+
"var APP_ORIGIN='__ONAIROS_ORIGIN__';",
|
|
12
|
+
"var APP_URL='__ONAIROS_URL__';",
|
|
13
|
+
"var API_URL='__API_URL__';",
|
|
14
|
+
"var token='__ONAIROS_TOKEN__';",
|
|
15
|
+
"var notifyApp=function(msg){try{if(window.opener&&!window.opener.closed){window.opener.postMessage(msg,APP_ORIGIN);return true;}}catch(_){}try{var p=window.open(APP_URL,'_blank');if(!p)return false;var n=0;var iv=setInterval(function(){try{if(!p||p.closed||n++>30){clearInterval(iv);return;}p.postMessage(msg,APP_ORIGIN);}catch(_){}},500);return true;}catch(_){return false;}};",
|
|
16
|
+
"var syncOrigin=(function(){try{return new URL(API_URL).origin}catch(_){return API_URL}})();var syncWin=null;var openSync=function(){try{syncWin=window.open(API_URL+'/grok-sync?receive=1','_dpSyncWin','width=480,height=560,toolbar=0,location=0,scrollbars=1,resizable=1');return syncWin}catch(_){return null}};openSync();",
|
|
17
|
+
"var hintEl=null;",
|
|
18
|
+
"var setHint=function(m){try{if(!hintEl){hintEl=document.createElement('div');hintEl.setAttribute('data-grok-export-status','1');hintEl.style.cssText='position:fixed;top:16px;right:16px;z-index:2147483647;max-width:280px;padding:8px 12px;border-radius:999px;background:rgba(15,23,42,.88);color:#fff;font:12px/1.2 -apple-system,BlinkMacSystemFont,Segoe UI,system-ui,sans-serif;box-shadow:0 10px 30px rgba(0,0,0,.22);pointer-events:none;opacity:.96;letter-spacing:.01em';document.body.appendChild(hintEl);}hintEl.textContent=String(m||'Preparing export...');}catch(_){}};",
|
|
19
|
+
"var clearHint=function(){try{if(hintEl&&hintEl.parentNode)hintEl.parentNode.removeChild(hintEl);}catch(_){}hintEl=null;};",
|
|
20
|
+
"var wait=function(ms){return new Promise(function(resolve){setTimeout(resolve,ms||0)});};",
|
|
21
|
+
"var clean=function(t){return String(t||'').replace(/\\s+$/,'').replace(/^\\s+/,'').replace(/\\n{3,}/g,'\\n\\n').trim();};",
|
|
22
|
+
"var normalizeTime=function(v){if(!v)return null;var n=Number(v);if(Number.isFinite(n))return new Date((n>9999999999?n:n*1000)).toISOString();var d=Date.parse(v);return Number.isFinite(d)?new Date(d).toISOString():null;};",
|
|
23
|
+
"var getText=function(item){if(!item)return '';var text='';if(typeof item.text==='string')text=item.text;if(!text&&typeof item.content==='string')text=item.content;if(!text&&Array.isArray(item.content))text=item.content.map(function(p){return typeof p==='string'?p:(p&&p.text)||'';}).join('');if(!text&&item.message&&typeof item.message==='string')text=item.message;return clean(text);};",
|
|
24
|
+
"var roleOf=function(item){var raw=String((item&&item.role)||(item&&item.author)||(item&&item.sender)||'').toLowerCase();return raw.indexOf('user')!==-1||raw.indexOf('human')!==-1?'user':'assistant';};",
|
|
25
|
+
"var normalizeConversation=function(id,title,data){var arr=Array.isArray(data)?data:((data&&data.responses)||(data&&data.items)||(data&&data.data)||(data&&data.messages)||[]);var messages=[];for(var i=0;i<arr.length;i++){var text=getText(arr[i]);if(!text)continue;messages.push({role:roleOf(arr[i]),content:text,timestamp:normalizeTime(arr[i].created_at||arr[i].timestamp||arr[i].time),meta:arr[i]});}messages.sort(function(a,b){return Date.parse(a.timestamp||0)-Date.parse(b.timestamp||0)});return messages.length?{id:id,title:title||'Grok Conversation',url:location.origin+location.pathname,model:'grok',messages:messages}:null;};",
|
|
26
|
+
"var idFromValue=function(v){var s=String(v||'');var m=s.match(/\\/(?:chat|c|conversations?)\\/([a-zA-Z0-9_-]{6,128})/i)||s.match(/[?&](?:id|conversation)=([a-zA-Z0-9_-]{6,128})/i)||s.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i);return m?(m[1]||m[0]):null;};",
|
|
27
|
+
"var collectIds=async function(){var ids=[];try{setHint('Finding conversations...');var res=await fetch('/rest/app-chat/conversations',{credentials:'include',headers:{accept:'application/json'},cache:'no-store'});if(res.ok){var list=await res.json();var items=Array.isArray(list)?list:((list&&list.conversations)||(list&&list.items)||(list&&list.data)||[]);for(var li=0;li<items.length&&ids.length<10;li++){var id=items[li]&&(items[li].id||items[li].conversationId||items[li].conversation_id);if(id&&ids.indexOf(id)===-1)ids.push(String(id));}}}catch(_){}var cur=idFromValue(location.href);if(cur&&ids.indexOf(cur)===-1)ids.unshift(cur);try{var links=[].slice.call(document.querySelectorAll('a[href*=\"/chat/\"],a[href*=\"/c/\"],a[href*=\"conversation\"]'));for(var ai=0;ai<links.length&&ids.length<10;ai++){var id=idFromValue(links[ai].getAttribute('href')||links[ai].href||'');if(id&&ids.indexOf(id)===-1)ids.push(id);}}catch(_){}return ids.slice(0,10);};",
|
|
28
|
+
"var extractDomCurrent=function(){var nodes=[];var sels=[{container:'[data-testid*=\"message\"]',user:'[data-testid*=\"user\"]'},{container:'article',user:'[class*=\"user\"],[class*=\"human\"]'},{container:'[class*=\"message\"]',user:'[class*=\"user\"],[class*=\"human\"]'},{container:'[class*=\"turn\"]',user:'[class*=\"user\"],[class*=\"human\"]'}];for(var si=0;si<sels.length&&!nodes.length;si++){var els=[].slice.call(document.querySelectorAll(sels[si].container));if(els.length<2)continue;for(var ei=0;ei<els.length;ei++){var text=clean(els[ei].innerText||els[ei].textContent||'');if(!text||text.length<2)continue;var isUser=!!els[ei].querySelector(sels[si].user)||els[ei].matches(sels[si].user);nodes.push({role:isUser?'user':'assistant',content:text,timestamp:null});}}if(!nodes.length){var all=[].slice.call(document.querySelectorAll('main *'));var last='';for(var wi=0;wi<all.length;wi++){var el=all[wi];if(el.children&&el.children.length>3)continue;if(el.closest&&el.closest('nav,header,footer,[class*=\"sidebar\"]'))continue;var txt=clean(el.innerText||el.textContent||'');if(!txt||txt.length<10)continue;var cls=String(el.className||'').toLowerCase();var isU=cls.indexOf('user')!==-1||cls.indexOf('human')!==-1||cls.indexOf('query')!==-1;var isA=cls.indexOf('assistant')!==-1||cls.indexOf('model')!==-1||cls.indexOf('response')!==-1||cls.indexOf('grok')!==-1;if(!isU&&!isA)continue;var role=isU?'user':'assistant';if(role===last)continue;last=role;nodes.push({role:role,content:txt,timestamp:null});}}return nodes.length?{id:idFromValue(location.href)||('current_'+Date.now()),title:(document.title||'Grok Conversation').replace(/\\s*-\\s*Grok.*$/i,'')||'Grok Conversation',url:location.href,model:'grok',messages:nodes}:null;};",
|
|
29
|
+
"setHint('Getting your Grok conversations...');",
|
|
30
|
+
"var ids=await collectIds();",
|
|
31
|
+
"var convos=[];",
|
|
32
|
+
"for(var i=0;i<ids.length&&convos.length<10;i++){try{setHint((i+1)+' / '+ids.length+' conversations');var detail=await fetch('/rest/app-chat/conversations/'+encodeURIComponent(ids[i])+'/responses',{credentials:'include',headers:{accept:'application/json'},cache:'no-store'});if(!detail.ok)continue;var conv=normalizeConversation(ids[i],'Grok Conversation',await detail.json());if(conv)convos.push(conv);if(i<ids.length-1)await wait(150);}catch(_){}}",
|
|
33
|
+
"var domConv=extractDomCurrent();if(domConv&&domConv.messages&&domConv.messages.length){var exists=false;for(var di=0;di<convos.length;di++){if(convos[di].id===domConv.id)exists=true;}if(!exists)convos.unshift(domConv);}",
|
|
34
|
+
"if(!convos.length){clearHint();alert('No Grok conversations found. Open an existing Grok chat, then retry.');return;}",
|
|
35
|
+
"setHint('Uploading to Onairos...');var data={type:'grok-export-data',exportId:String(Date.now())+'_'+Math.random().toString(36).slice(2),convos:convos,token:token,platform:'web-grok'};try{notifyApp(data)}catch(_){}if(!syncWin||syncWin.closed)openSync();var sends=0;var sendIv=setInterval(function(){try{if(!syncWin||syncWin.closed||sends++>40){clearInterval(sendIv);return;}syncWin.postMessage({type:'onairos-llm-sync-payload',platform:'web-grok',payload:data},syncOrigin);}catch(_){}},500);setHint('Sync in progress - see popup');setTimeout(clearHint,2500);",
|
|
36
|
+
"}catch(e){try{clearHint()}catch(_){}alert('Export error: '+(e&&e.message?e.message:e));}})();",
|
|
37
|
+
].join('');
|
|
38
|
+
|
|
39
|
+
const PENDING_IMPORT_KEY = '_pending_grok_import';
|
|
40
|
+
const SYNC_SUCCESS_KEY = 'onairos_grok_sync_success';
|
|
41
|
+
|
|
42
|
+
export const getOnairosGrokBookmarklet = () => GROK_BOOKMARKLET_HREF;
|
|
43
|
+
|
|
44
|
+
const encodePayload = (value) => {
|
|
45
|
+
const json = JSON.stringify(value || {});
|
|
46
|
+
try {
|
|
47
|
+
return btoa(unescape(encodeURIComponent(json)));
|
|
48
|
+
} catch (_) {
|
|
49
|
+
return btoa(json);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const generateDataHash = async (value) => {
|
|
54
|
+
try {
|
|
55
|
+
const encoded = new TextEncoder().encode(JSON.stringify(value || {}));
|
|
56
|
+
const digest = await crypto.subtle.digest('SHA-256', encoded);
|
|
57
|
+
return `sha256-${Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, '0')).join('')}`;
|
|
58
|
+
} catch (_) {
|
|
59
|
+
return `sha256-${Date.now()}`;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getGrokIdentifierForAccountCheck = () => {
|
|
64
|
+
try {
|
|
65
|
+
const user = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
66
|
+
return (
|
|
67
|
+
user.email ||
|
|
68
|
+
user.userEmail ||
|
|
69
|
+
user.identifier ||
|
|
70
|
+
user.userName ||
|
|
71
|
+
user.username ||
|
|
72
|
+
localStorage.getItem('onairos_user_email') ||
|
|
73
|
+
null
|
|
74
|
+
);
|
|
75
|
+
} catch (_) {
|
|
76
|
+
return localStorage.getItem('onairos_user_email') || null;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const markGrokConnectedLocally = () => {
|
|
81
|
+
try {
|
|
82
|
+
const storedConnections = JSON.parse(localStorage.getItem('onairos_connected_accounts') || '{}');
|
|
83
|
+
storedConnections.Grok = true;
|
|
84
|
+
localStorage.setItem('onairos_connected_accounts', JSON.stringify(storedConnections));
|
|
85
|
+
} catch (_) {}
|
|
86
|
+
try {
|
|
87
|
+
const connectedAccounts = JSON.parse(localStorage.getItem('connectedAccounts') || '[]');
|
|
88
|
+
if (!connectedAccounts.includes('Grok')) {
|
|
89
|
+
connectedAccounts.push('Grok');
|
|
90
|
+
localStorage.setItem('connectedAccounts', JSON.stringify(connectedAccounts));
|
|
91
|
+
}
|
|
92
|
+
} catch (_) {}
|
|
93
|
+
try {
|
|
94
|
+
const userData = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
95
|
+
if (!Array.isArray(userData.connectedAccounts)) userData.connectedAccounts = [];
|
|
96
|
+
if (!userData.connectedAccounts.includes('Grok')) {
|
|
97
|
+
userData.connectedAccounts.push('Grok');
|
|
98
|
+
localStorage.setItem('onairosUser', JSON.stringify(userData));
|
|
99
|
+
}
|
|
100
|
+
} catch (_) {}
|
|
101
|
+
try {
|
|
102
|
+
window.dispatchEvent(new CustomEvent('connected-accounts-updated', { detail: { platform: 'Grok' } }));
|
|
103
|
+
} catch (_) {}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const seenGrokExportIds = new Set();
|
|
107
|
+
|
|
108
|
+
const notifyLlmSyncPopup = (popupId, status, detail = {}) => {
|
|
109
|
+
if (!popupId) return;
|
|
110
|
+
try {
|
|
111
|
+
const popup = window.open('', '_dpSyncWin');
|
|
112
|
+
if (popup && !popup.closed) {
|
|
113
|
+
popup.postMessage({
|
|
114
|
+
type: 'onairos-llm-sync-status',
|
|
115
|
+
popupId,
|
|
116
|
+
status,
|
|
117
|
+
...detail,
|
|
118
|
+
}, '*');
|
|
119
|
+
}
|
|
120
|
+
} catch (_) {}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const uploadGrokExportData = async (convos, exportId = '') => {
|
|
124
|
+
const dedupeKey = exportId || JSON.stringify({ count: convos?.length || 0, first: convos?.[0]?.id || '' });
|
|
125
|
+
if (seenGrokExportIds.has(dedupeKey)) return false;
|
|
126
|
+
seenGrokExportIds.add(dedupeKey);
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const userData = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
130
|
+
const jwt = getUserToken() || userData.token || userData.jwt || localStorage.getItem('onairos_user_token') || '';
|
|
131
|
+
if (!jwt) {
|
|
132
|
+
console.warn('[Grok] Cannot upload: missing Onairos user token');
|
|
133
|
+
try {
|
|
134
|
+
localStorage.setItem(PENDING_IMPORT_KEY, JSON.stringify({ convos, exportId, receivedAt: Date.now(), reason: 'missing-token' }));
|
|
135
|
+
} catch (_) {}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const baseUrl = (typeof window !== 'undefined' && window.onairosBaseUrl) || getApiBaseUrl();
|
|
140
|
+
const apiKey = getApiKey();
|
|
141
|
+
const identifier = getGrokIdentifierForAccountCheck();
|
|
142
|
+
const conversationData = {
|
|
143
|
+
platform: 'grok',
|
|
144
|
+
conversations: convos,
|
|
145
|
+
timestamp: new Date().toISOString(),
|
|
146
|
+
};
|
|
147
|
+
const resp = await fetch(`${baseUrl}/llm-data/store`, {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: {
|
|
150
|
+
'Content-Type': 'application/json',
|
|
151
|
+
Authorization: `Bearer ${jwt}`,
|
|
152
|
+
...(apiKey ? { 'x-api-key': apiKey } : {}),
|
|
153
|
+
...(identifier ? { 'X-Onairos-User': identifier } : {}),
|
|
154
|
+
},
|
|
155
|
+
body: JSON.stringify({
|
|
156
|
+
encryptedData: encodePayload(conversationData),
|
|
157
|
+
encryptionMetadata: {
|
|
158
|
+
algorithm: 'AES-GCM',
|
|
159
|
+
keyDerivation: 'PBKDF2',
|
|
160
|
+
iterations: 100000,
|
|
161
|
+
},
|
|
162
|
+
authentication: {
|
|
163
|
+
username: identifier || userData.username || userData.email || '',
|
|
164
|
+
timestamp: Date.now(),
|
|
165
|
+
},
|
|
166
|
+
integrity: {
|
|
167
|
+
hash: await generateDataHash(conversationData),
|
|
168
|
+
algorithm: 'SHA-256',
|
|
169
|
+
},
|
|
170
|
+
platform: 'grok',
|
|
171
|
+
source: 'web_bookmarklet',
|
|
172
|
+
metadata: {
|
|
173
|
+
importedAt: new Date().toISOString(),
|
|
174
|
+
conversationCount: Array.isArray(convos) ? convos.length : 0,
|
|
175
|
+
},
|
|
176
|
+
}),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (!resp.ok) {
|
|
180
|
+
console.warn('[Grok] /llm-data/store failed', resp.status, await resp.text().catch(() => ''));
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
console.info('[Grok] Stored export via /llm-data/store', { conversationCount: convos?.length || 0 });
|
|
185
|
+
markGrokConnectedLocally();
|
|
186
|
+
return true;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.warn('[Grok] Upload failed before backend storage', error);
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
if (typeof window !== 'undefined') {
|
|
194
|
+
const handleGrokExport = (event) => {
|
|
195
|
+
if (event.data?.type !== 'grok-export-data') return;
|
|
196
|
+
try {
|
|
197
|
+
if (event.source) {
|
|
198
|
+
event.source.postMessage({ type: 'grok-export-ack' }, event.origin);
|
|
199
|
+
}
|
|
200
|
+
} catch (_) {}
|
|
201
|
+
if (!window.__onairosGrokModalOpen) {
|
|
202
|
+
uploadGrokExportData(event.data.convos, event.data.exportId).then((stored) => {
|
|
203
|
+
const statusMessage = {
|
|
204
|
+
platform: 'Grok',
|
|
205
|
+
count: Array.isArray(event.data.convos) ? event.data.convos.length : 0,
|
|
206
|
+
message: stored ? '' : 'Could not store Grok data. Check the Onairos app tab.',
|
|
207
|
+
};
|
|
208
|
+
notifyLlmSyncPopup(event.data.popupId, stored ? 'success' : 'error', statusMessage);
|
|
209
|
+
try {
|
|
210
|
+
event.source?.postMessage({
|
|
211
|
+
type: 'onairos-llm-sync-status',
|
|
212
|
+
popupId: event.data.popupId,
|
|
213
|
+
status: stored ? 'success' : 'error',
|
|
214
|
+
...statusMessage,
|
|
215
|
+
}, event.origin);
|
|
216
|
+
} catch (_) {}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
window.addEventListener('message', handleGrokExport);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export default function ConnectGrokModal({ open, onClose, onConnected }) {
|
|
224
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
225
|
+
const [copied, setCopied] = useState(false);
|
|
226
|
+
const [bookmarkletHrefFinal, setBookmarkletHrefFinal] = useState(() => {
|
|
227
|
+
if (typeof window === 'undefined') return '#';
|
|
228
|
+
const origin = window.location.origin;
|
|
229
|
+
const jwt = getUserToken() || '';
|
|
230
|
+
const baseUrl = (window.onairosBaseUrl) || getApiBaseUrl();
|
|
231
|
+
return GROK_BOOKMARKLET_HREF
|
|
232
|
+
.replace(/__ONAIROS_ORIGIN__/g, origin)
|
|
233
|
+
.replace(/__ONAIROS_URL__/g, window.location.href)
|
|
234
|
+
.replace(/__API_URL__/g, baseUrl)
|
|
235
|
+
.replace(/__ONAIROS_TOKEN__/g, jwt);
|
|
236
|
+
});
|
|
237
|
+
const [mobileCodeFinal, setMobileCodeFinal] = useState('#');
|
|
238
|
+
const bookmarkletRef = useRef(null);
|
|
239
|
+
const syncTimeoutRef = useRef(null);
|
|
240
|
+
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
setIsMobile(window.innerWidth <= 768);
|
|
243
|
+
const handleResize = () => setIsMobile(window.innerWidth <= 768);
|
|
244
|
+
window.addEventListener('resize', handleResize);
|
|
245
|
+
return () => window.removeEventListener('resize', handleResize);
|
|
246
|
+
}, []);
|
|
247
|
+
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
if (!open) return () => {};
|
|
250
|
+
window.__onairosGrokModalOpen = true;
|
|
251
|
+
const origin = window.location.origin;
|
|
252
|
+
const jwt = getUserToken() || '';
|
|
253
|
+
const baseUrl = (typeof window !== 'undefined' && window.onairosBaseUrl) || getApiBaseUrl();
|
|
254
|
+
const href = GROK_BOOKMARKLET_HREF
|
|
255
|
+
.replace(/__ONAIROS_ORIGIN__/g, origin)
|
|
256
|
+
.replace(/__ONAIROS_URL__/g, window.location.href)
|
|
257
|
+
.replace(/__API_URL__/g, baseUrl)
|
|
258
|
+
.replace(/__ONAIROS_TOKEN__/g, jwt);
|
|
259
|
+
setBookmarkletHrefFinal(href);
|
|
260
|
+
setMobileCodeFinal(href);
|
|
261
|
+
if (bookmarkletRef.current && href) {
|
|
262
|
+
bookmarkletRef.current.href = href;
|
|
263
|
+
bookmarkletRef.current.title = 'Export Grok';
|
|
264
|
+
}
|
|
265
|
+
return () => {
|
|
266
|
+
window.__onairosGrokModalOpen = false;
|
|
267
|
+
};
|
|
268
|
+
}, [open]);
|
|
269
|
+
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
if (!open) return () => {};
|
|
272
|
+
const baseUrl = (typeof window !== 'undefined' && window.onairosBaseUrl) || getApiBaseUrl();
|
|
273
|
+
const apiKey = getApiKey();
|
|
274
|
+
|
|
275
|
+
const isGrokConnectedFromAccountStatus = (data) => {
|
|
276
|
+
try {
|
|
277
|
+
const acct = data?.AccountInfo?.accounts?.grok || data?.AccountInfo?.accounts?.Grok;
|
|
278
|
+
if (acct?.connected === true) return true;
|
|
279
|
+
const connectedPlatforms = data?.accountStatus?.connectedPlatforms;
|
|
280
|
+
if (Array.isArray(connectedPlatforms)) {
|
|
281
|
+
return connectedPlatforms.some((p) => String(p).toLowerCase().includes('grok'));
|
|
282
|
+
}
|
|
283
|
+
const connections = data?.AccountInfo?.connections;
|
|
284
|
+
if (Array.isArray(connections)) {
|
|
285
|
+
return connections.some((p) => String(p).toLowerCase().includes('grok'));
|
|
286
|
+
}
|
|
287
|
+
if (connections && typeof connections === 'object') {
|
|
288
|
+
return connections.Grok || connections.grok || false;
|
|
289
|
+
}
|
|
290
|
+
} catch (_) {
|
|
291
|
+
// Keep polling.
|
|
292
|
+
}
|
|
293
|
+
return false;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const markConnectedLocallyFromSync = () => {
|
|
297
|
+
if (syncTimeoutRef.current) {
|
|
298
|
+
window.clearTimeout(syncTimeoutRef.current);
|
|
299
|
+
syncTimeoutRef.current = null;
|
|
300
|
+
}
|
|
301
|
+
markGrokConnectedLocally();
|
|
302
|
+
try {
|
|
303
|
+
localStorage.removeItem(SYNC_SUCCESS_KEY);
|
|
304
|
+
} catch (_) {}
|
|
305
|
+
|
|
306
|
+
if (typeof onConnected === 'function') onConnected();
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const uploadExportData = async (convos) => {
|
|
310
|
+
try {
|
|
311
|
+
const stored = await uploadGrokExportData(convos);
|
|
312
|
+
if (stored) {
|
|
313
|
+
markConnectedLocallyFromSync();
|
|
314
|
+
}
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.warn('[Grok] Upload failed before backend storage', error);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const processPendingImport = (raw) => {
|
|
321
|
+
try {
|
|
322
|
+
const { convos } = JSON.parse(raw);
|
|
323
|
+
uploadExportData(convos);
|
|
324
|
+
} catch (_) {}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const pendingRaw = localStorage.getItem(PENDING_IMPORT_KEY);
|
|
328
|
+
if (pendingRaw) {
|
|
329
|
+
localStorage.removeItem(PENDING_IMPORT_KEY);
|
|
330
|
+
processPendingImport(pendingRaw);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const pollInterval = setInterval(() => {
|
|
334
|
+
const raw = localStorage.getItem(PENDING_IMPORT_KEY);
|
|
335
|
+
if (raw) {
|
|
336
|
+
localStorage.removeItem(PENDING_IMPORT_KEY);
|
|
337
|
+
processPendingImport(raw);
|
|
338
|
+
}
|
|
339
|
+
}, 1000);
|
|
340
|
+
|
|
341
|
+
const connectionCheck = setInterval(() => {
|
|
342
|
+
try {
|
|
343
|
+
const storedConnections = JSON.parse(localStorage.getItem('onairos_connected_accounts') || '{}');
|
|
344
|
+
const grokSyncSuccess = localStorage.getItem(SYNC_SUCCESS_KEY);
|
|
345
|
+
if (storedConnections.grok || storedConnections.Grok || grokSyncSuccess === 'true') {
|
|
346
|
+
markConnectedLocallyFromSync();
|
|
347
|
+
clearInterval(connectionCheck);
|
|
348
|
+
clearInterval(backendPoll);
|
|
349
|
+
}
|
|
350
|
+
} catch (_) {}
|
|
351
|
+
}, 1000);
|
|
352
|
+
|
|
353
|
+
let backendPollInFlight = false;
|
|
354
|
+
const backendPoll = setInterval(async () => {
|
|
355
|
+
if (!open || backendPollInFlight) return;
|
|
356
|
+
const identifier = getGrokIdentifierForAccountCheck();
|
|
357
|
+
if (!identifier) return;
|
|
358
|
+
|
|
359
|
+
backendPollInFlight = true;
|
|
360
|
+
try {
|
|
361
|
+
const resp = await fetch(`${baseUrl}/getAccountInfo/email`, {
|
|
362
|
+
method: 'POST',
|
|
363
|
+
headers: {
|
|
364
|
+
'Content-Type': 'application/json',
|
|
365
|
+
...(apiKey ? { 'x-api-key': apiKey } : {}),
|
|
366
|
+
},
|
|
367
|
+
body: JSON.stringify({ Info: { identifier: String(identifier).trim().toLowerCase() } }),
|
|
368
|
+
});
|
|
369
|
+
if (resp.ok && isGrokConnectedFromAccountStatus(await resp.json())) {
|
|
370
|
+
clearInterval(connectionCheck);
|
|
371
|
+
clearInterval(backendPoll);
|
|
372
|
+
markConnectedLocallyFromSync();
|
|
373
|
+
}
|
|
374
|
+
} catch (_) {
|
|
375
|
+
// Keep polling.
|
|
376
|
+
} finally {
|
|
377
|
+
backendPollInFlight = false;
|
|
378
|
+
}
|
|
379
|
+
}, 2000);
|
|
380
|
+
|
|
381
|
+
const handleMessage = (event) => {
|
|
382
|
+
if (event.data?.type === 'grok-export-data') {
|
|
383
|
+
const { convos } = event.data;
|
|
384
|
+
localStorage.removeItem(PENDING_IMPORT_KEY);
|
|
385
|
+
if (event.source) {
|
|
386
|
+
try { event.source.postMessage({ type: 'grok-export-ack' }, event.origin); } catch (_) {}
|
|
387
|
+
}
|
|
388
|
+
uploadGrokExportData(convos, event.data.exportId).then((stored) => {
|
|
389
|
+
const statusMessage = {
|
|
390
|
+
platform: 'Grok',
|
|
391
|
+
count: Array.isArray(convos) ? convos.length : 0,
|
|
392
|
+
message: stored ? '' : 'Could not store Grok data. Check the Onairos app tab.',
|
|
393
|
+
};
|
|
394
|
+
notifyLlmSyncPopup(event.data.popupId, stored ? 'success' : 'error', statusMessage);
|
|
395
|
+
try {
|
|
396
|
+
event.source?.postMessage({
|
|
397
|
+
type: 'onairos-llm-sync-status',
|
|
398
|
+
popupId: event.data.popupId,
|
|
399
|
+
status: stored ? 'success' : 'error',
|
|
400
|
+
...statusMessage,
|
|
401
|
+
}, event.origin);
|
|
402
|
+
} catch (_) {}
|
|
403
|
+
if (stored) markConnectedLocallyFromSync();
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (event.data?.type === 'llm-import-success' && String(event.data.platform || '').includes('grok')) {
|
|
408
|
+
markConnectedLocallyFromSync();
|
|
409
|
+
clearInterval(connectionCheck);
|
|
410
|
+
clearInterval(backendPoll);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
window.addEventListener('message', handleMessage);
|
|
414
|
+
|
|
415
|
+
return () => {
|
|
416
|
+
window.removeEventListener('message', handleMessage);
|
|
417
|
+
clearInterval(pollInterval);
|
|
418
|
+
clearInterval(connectionCheck);
|
|
419
|
+
clearInterval(backendPoll);
|
|
420
|
+
if (syncTimeoutRef.current) {
|
|
421
|
+
window.clearTimeout(syncTimeoutRef.current);
|
|
422
|
+
syncTimeoutRef.current = null;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}, [open, onConnected]);
|
|
426
|
+
|
|
427
|
+
const handleCopyCode = () => {
|
|
428
|
+
navigator.clipboard.writeText(mobileCodeFinal);
|
|
429
|
+
setCopied(true);
|
|
430
|
+
setTimeout(() => setCopied(false), 2000);
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
const handleGotIt = () => {
|
|
434
|
+
if (typeof onClose === 'function') onClose();
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
if (!open) return null;
|
|
438
|
+
|
|
439
|
+
return ReactDOM.createPortal(
|
|
440
|
+
<div style={{ position: 'fixed', inset: 0, zIndex: 2147483647, pointerEvents: 'auto' }}>
|
|
441
|
+
<style>{`
|
|
442
|
+
@keyframes gentlePulse {
|
|
443
|
+
0%, 100% { box-shadow: 0 0 0 0 rgba(148, 163, 184, 0.35); }
|
|
444
|
+
50% { box-shadow: 0 0 0 10px rgba(148, 163, 184, 0); }
|
|
445
|
+
}
|
|
446
|
+
.bookmarklet-button {
|
|
447
|
+
background: rgba(15, 23, 42, 0.85);
|
|
448
|
+
border-radius: 9999px;
|
|
449
|
+
border: 1px solid rgba(255,255,255,0.16);
|
|
450
|
+
backdrop-filter: blur(18px);
|
|
451
|
+
}
|
|
452
|
+
.bookmarklet-button:hover { background: rgba(15, 23, 42, 0.92); }
|
|
453
|
+
@keyframes fadeInScale {
|
|
454
|
+
0% { opacity: 0; transform: translateY(8px) scale(0.96); }
|
|
455
|
+
100% { opacity: 1; transform: translateY(0) scale(1); }
|
|
456
|
+
}
|
|
457
|
+
.grok-modal-card { animation: fadeInScale 200ms cubic-bezier(0.16, 1, 0.3, 1); }
|
|
458
|
+
.step-circle {
|
|
459
|
+
background: rgba(15, 23, 42, 0.9);
|
|
460
|
+
min-width: 28px;
|
|
461
|
+
width: 28px;
|
|
462
|
+
height: 28px;
|
|
463
|
+
}
|
|
464
|
+
.grok-got-it-button {
|
|
465
|
+
color: #FFFFFF !important;
|
|
466
|
+
background-color: rgba(15, 23, 42, 0.8) !important;
|
|
467
|
+
}
|
|
468
|
+
.grok-got-it-button:hover { background-color: rgba(15, 23, 42, 0.9) !important; }
|
|
469
|
+
.grok-got-it-button * { color: #FFFFFF !important; }
|
|
470
|
+
@media (max-width: 768px) {
|
|
471
|
+
.grok-modal-backdrop { align-items: flex-end !important; padding: 0 !important; }
|
|
472
|
+
.grok-modal-card {
|
|
473
|
+
max-width: 100% !important;
|
|
474
|
+
height: 90vh !important;
|
|
475
|
+
max-height: 90vh !important;
|
|
476
|
+
border-radius: 24px 24px 0 0 !important;
|
|
477
|
+
animation: slideUpFromBottom 300ms cubic-bezier(0.16, 1, 0.3, 1) !important;
|
|
478
|
+
display: flex;
|
|
479
|
+
flex-direction: column;
|
|
480
|
+
}
|
|
481
|
+
.grok-modal-content { overflow-y: auto; flex: 1; }
|
|
482
|
+
}
|
|
483
|
+
@keyframes slideUpFromBottom {
|
|
484
|
+
0% { transform: translateY(100%); }
|
|
485
|
+
100% { transform: translateY(0); }
|
|
486
|
+
}
|
|
487
|
+
`}</style>
|
|
488
|
+
|
|
489
|
+
<div className="grok-modal-backdrop fixed inset-0 flex items-center justify-center p-4 bg-black/60" style={{ zIndex: 2147483647 }}>
|
|
490
|
+
<div
|
|
491
|
+
className="grok-modal-card w-full max-w-md rounded-3xl shadow-2xl border border-white/10 overflow-hidden text-white relative"
|
|
492
|
+
style={{
|
|
493
|
+
background:
|
|
494
|
+
'linear-gradient(135deg, rgba(3, 7, 18, 0.97) 0%, rgba(17, 24, 39, 0.94) 52%, rgba(31, 41, 55, 0.95) 100%)',
|
|
495
|
+
boxShadow:
|
|
496
|
+
'inset 0 1px 0 0 rgba(255, 255, 255, 0.1), 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 100px rgba(148, 163, 184, 0.15)',
|
|
497
|
+
}}
|
|
498
|
+
>
|
|
499
|
+
<div className="relative px-5 py-4 border-b border-white/10 bg-white/5 flex-shrink-0">
|
|
500
|
+
<button
|
|
501
|
+
onClick={onClose}
|
|
502
|
+
aria-label="Close"
|
|
503
|
+
type="button"
|
|
504
|
+
className="onairos-close-btn absolute right-3 top-3 inline-flex items-center justify-center rounded-full transition-all hover:scale-105 z-50 cursor-pointer"
|
|
505
|
+
style={{
|
|
506
|
+
width: 28,
|
|
507
|
+
height: 28,
|
|
508
|
+
padding: 0,
|
|
509
|
+
background: 'rgba(255, 255, 255, 0.08)',
|
|
510
|
+
border: '1px solid rgba(255, 255, 255, 0.18)',
|
|
511
|
+
backdropFilter: 'blur(8px)',
|
|
512
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
513
|
+
color: '#ffffff',
|
|
514
|
+
}}
|
|
515
|
+
onMouseEnter={(e) => { e.currentTarget.style.background = 'rgba(255,255,255,0.16)'; }}
|
|
516
|
+
onMouseLeave={(e) => { e.currentTarget.style.background = 'rgba(255,255,255,0.08)'; }}
|
|
517
|
+
>
|
|
518
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden>
|
|
519
|
+
<path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
|
520
|
+
</svg>
|
|
521
|
+
</button>
|
|
522
|
+
|
|
523
|
+
<h2 className="text-xl font-semibold pr-8 text-white">{isMobile ? 'Export Grok' : 'Connect Grok'}</h2>
|
|
524
|
+
<p className="text-sm mt-0.5 text-white">Import your recent chats.</p>
|
|
525
|
+
</div>
|
|
526
|
+
|
|
527
|
+
<div className="px-5 py-4 space-y-4 grok-modal-content">
|
|
528
|
+
{isMobile ? (
|
|
529
|
+
<>
|
|
530
|
+
<div className="flex gap-3">
|
|
531
|
+
<div className="flex-shrink-0">
|
|
532
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
533
|
+
<span className="text-white font-bold text-sm">1</span>
|
|
534
|
+
</div>
|
|
535
|
+
</div>
|
|
536
|
+
<div className="flex-1 pt-0.5">
|
|
537
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Copy the bookmark code</h3>
|
|
538
|
+
<button
|
|
539
|
+
onClick={handleCopyCode}
|
|
540
|
+
className="mt-1 w-full flex items-center justify-center gap-2 py-3 bg-white/10 rounded-xl text-sm font-medium hover:bg-white/20 active:scale-95 transition-all text-slate-200 border border-slate-500/30"
|
|
541
|
+
>
|
|
542
|
+
{copied ? 'Copied' : 'Copy code'}
|
|
543
|
+
</button>
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
|
|
547
|
+
<div className="flex gap-3">
|
|
548
|
+
<div className="flex-shrink-0">
|
|
549
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
550
|
+
<span className="text-white font-bold text-sm">2</span>
|
|
551
|
+
</div>
|
|
552
|
+
</div>
|
|
553
|
+
<div className="flex-1 pt-0.5">
|
|
554
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Add a bookmark</h3>
|
|
555
|
+
<p className="text-xs text-slate-200 leading-relaxed mb-2">
|
|
556
|
+
Add a bookmark, then paste the code into the bookmark URL.
|
|
557
|
+
</p>
|
|
558
|
+
</div>
|
|
559
|
+
</div>
|
|
560
|
+
|
|
561
|
+
<div className="flex gap-3">
|
|
562
|
+
<div className="flex-shrink-0">
|
|
563
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
564
|
+
<span className="text-white font-bold text-sm">3</span>
|
|
565
|
+
</div>
|
|
566
|
+
</div>
|
|
567
|
+
<div className="flex-1 pt-0.5">
|
|
568
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Run it on Grok</h3>
|
|
569
|
+
<button
|
|
570
|
+
type="button"
|
|
571
|
+
onClick={() => window.open('https://grok.com', '_blank')}
|
|
572
|
+
className="mt-2 text-xs bg-slate-700 hover:bg-slate-600 text-white px-3 py-1.5 rounded-lg inline-flex items-center gap-1"
|
|
573
|
+
>
|
|
574
|
+
Open Grok
|
|
575
|
+
</button>
|
|
576
|
+
<p className="text-xs text-slate-300 mt-2">In the address bar, search your bookmark name and tap it.</p>
|
|
577
|
+
</div>
|
|
578
|
+
</div>
|
|
579
|
+
</>
|
|
580
|
+
) : (
|
|
581
|
+
<>
|
|
582
|
+
<div className="flex gap-3">
|
|
583
|
+
<div className="flex-shrink-0">
|
|
584
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
585
|
+
<span className="text-white font-bold text-sm">1</span>
|
|
586
|
+
</div>
|
|
587
|
+
</div>
|
|
588
|
+
<div className="flex-1 pt-0.5">
|
|
589
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Drag this button to your bookmarks bar</h3>
|
|
590
|
+
<div className="relative inline-block mt-2">
|
|
591
|
+
<div className="absolute inset-0 rounded-full" style={{ animation: 'gentlePulse 2s ease-in-out infinite' }} />
|
|
592
|
+
<a
|
|
593
|
+
ref={bookmarkletRef}
|
|
594
|
+
href={bookmarkletHrefFinal || '#'}
|
|
595
|
+
title="Export Grok"
|
|
596
|
+
aria-label="Export Grok"
|
|
597
|
+
draggable="true"
|
|
598
|
+
onDragStart={(e) => {
|
|
599
|
+
try {
|
|
600
|
+
const bookmarkTitle = 'Export Grok';
|
|
601
|
+
const href = bookmarkletRef.current?.href || bookmarkletHrefFinal || '#';
|
|
602
|
+
if (bookmarkletRef.current && href) bookmarkletRef.current.href = href;
|
|
603
|
+
if (bookmarkletRef.current) bookmarkletRef.current.title = bookmarkTitle;
|
|
604
|
+
|
|
605
|
+
const ua = navigator?.userAgent || '';
|
|
606
|
+
const isChromium =
|
|
607
|
+
/\bChrome\/|\bChromium\//.test(ua) && !/\bEdg\/|\bOPR\//.test(ua);
|
|
608
|
+
if (isChromium) return;
|
|
609
|
+
|
|
610
|
+
const html = `<a href="${href}">${bookmarkTitle}</a>`;
|
|
611
|
+
e.dataTransfer.setData('text/uri-list', href);
|
|
612
|
+
e.dataTransfer.setData('text/plain', href);
|
|
613
|
+
e.dataTransfer.setData('text/html', html);
|
|
614
|
+
e.dataTransfer.setData('text/x-moz-url', `${href}\n${bookmarkTitle}`);
|
|
615
|
+
e.dataTransfer.effectAllowed = 'copy';
|
|
616
|
+
} catch (err) {
|
|
617
|
+
console.warn('Drag start error:', err);
|
|
618
|
+
}
|
|
619
|
+
}}
|
|
620
|
+
onClick={(e) => {
|
|
621
|
+
e.preventDefault();
|
|
622
|
+
alert('Drag this button to your bookmarks bar.');
|
|
623
|
+
}}
|
|
624
|
+
className="bookmarklet-button relative inline-flex items-center gap-1.5 px-4 py-2 font-medium cursor-move select-none transition-all hover:scale-[1.03]"
|
|
625
|
+
suppressHydrationWarning
|
|
626
|
+
>
|
|
627
|
+
<span className="text-base">✨</span>
|
|
628
|
+
<span className="text-sm">Export Grok</span>
|
|
629
|
+
</a>
|
|
630
|
+
</div>
|
|
631
|
+
</div>
|
|
632
|
+
</div>
|
|
633
|
+
|
|
634
|
+
<div className="flex gap-3">
|
|
635
|
+
<div className="flex-shrink-0">
|
|
636
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
637
|
+
<span className="text-white font-bold text-sm">2</span>
|
|
638
|
+
</div>
|
|
639
|
+
</div>
|
|
640
|
+
<div className="flex-1 pt-0.5">
|
|
641
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Open Grok</h3>
|
|
642
|
+
<button
|
|
643
|
+
type="button"
|
|
644
|
+
onClick={() => window.open('https://grok.com', '_blank')}
|
|
645
|
+
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-medium transition-all hover:scale-[1.02] active:scale-[0.98]"
|
|
646
|
+
style={{
|
|
647
|
+
background: 'linear-gradient(135deg, #334155 0%, #020617 100%)',
|
|
648
|
+
color: '#ffffff',
|
|
649
|
+
boxShadow: '0 0 25px rgba(148, 163, 184, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.2)',
|
|
650
|
+
}}
|
|
651
|
+
>
|
|
652
|
+
<svg
|
|
653
|
+
className="w-3.5 h-3.5"
|
|
654
|
+
fill="none"
|
|
655
|
+
stroke="currentColor"
|
|
656
|
+
viewBox="0 0 24 24"
|
|
657
|
+
>
|
|
658
|
+
<path
|
|
659
|
+
strokeLinecap="round"
|
|
660
|
+
strokeLinejoin="round"
|
|
661
|
+
strokeWidth={2}
|
|
662
|
+
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
|
|
663
|
+
/>
|
|
664
|
+
</svg>
|
|
665
|
+
Open Grok
|
|
666
|
+
</button>
|
|
667
|
+
</div>
|
|
668
|
+
</div>
|
|
669
|
+
|
|
670
|
+
<div className="flex gap-3">
|
|
671
|
+
<div className="flex-shrink-0">
|
|
672
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
673
|
+
<span className="text-white font-bold text-sm">3</span>
|
|
674
|
+
</div>
|
|
675
|
+
</div>
|
|
676
|
+
<div className="flex-1 pt-0.5">
|
|
677
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Click the bookmark</h3>
|
|
678
|
+
<p className="text-xs text-slate-200">
|
|
679
|
+
Click <strong className="text-white">"Export Grok"</strong> in your bookmarks bar.
|
|
680
|
+
</p>
|
|
681
|
+
</div>
|
|
682
|
+
</div>
|
|
683
|
+
</>
|
|
684
|
+
)}
|
|
685
|
+
</div>
|
|
686
|
+
|
|
687
|
+
<div className="px-5 py-4 bg-white/5 border-t border-white/10 flex-shrink-0">
|
|
688
|
+
<button
|
|
689
|
+
type="button"
|
|
690
|
+
onClick={handleGotIt}
|
|
691
|
+
className="w-full px-4 py-2.5 rounded-full font-medium text-sm transition-all hover:scale-[1.01] active:scale-[0.99] shadow-[0_10px_30px_rgba(15,23,42,0.45)] border border-white/40 grok-got-it-button"
|
|
692
|
+
>
|
|
693
|
+
<span>{isMobile ? 'Close' : 'Got it!'}</span>
|
|
694
|
+
</button>
|
|
695
|
+
</div>
|
|
696
|
+
</div>
|
|
697
|
+
</div>
|
|
698
|
+
</div>,
|
|
699
|
+
document.body
|
|
700
|
+
);
|
|
701
|
+
}
|