MCPcopy Create free account
hub / github.com/msgbyte/tailchat / useInjectTianjiScript

Function useInjectTianjiScript

client/web/src/hooks/useInjectTianjiScript.ts:3–28  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import { useDataReady, useGlobalConfigStore } from 'tailchat-shared';
2
3export function useInjectTianjiScript() {
4 const { tianji } = useGlobalConfigStore();
5
6 useDataReady(
7 () =>
8 typeof tianji.scriptUrl === 'string' &&
9 typeof tianji.websiteId === 'string' &&
10 tianji.websiteId.length > 0,
11 () => {
12 if (!tianji.scriptUrl) {
13 console.error(
14 'Cannot inject Tianji script because of scriptUrl not cool:',
15 tianji.scriptUrl
16 );
17 return;
18 }
19
20 const el = document.createElement('script');
21 el.src = tianji.scriptUrl;
22 el.setAttribute('data-website-id', String(tianji.websiteId));
23 el.setAttribute('async', 'async');
24 el.setAttribute('defer', 'defer');
25 document.head.append(el);
26 }
27 );
28}

Callers 1

App.tsxFile · 0.90

Calls 3

useDataReadyFunction · 0.85
errorMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected