@@ -11,18 +11,17 @@ declare global {
1111 }
1212}
1313
14- const loadScript = ( ) => {
15- if ( window . drift ) return
14+ /* eslint-disable */
15+ const loadScript = ( ) : boolean => {
16+ if ( window . drift ) return false
1617
1718 ! ( function ( ) {
1819 const t = ( window . driftt = window . drift = window . driftt || [ ] )
1920 if ( ! t . init ) {
2021 if ( t . invoked ) {
2122 return void (
2223 window . console &&
23- //eslint-disable-next-line no-console
2424 console . error &&
25- //eslint-disable-next-line no-console
2625 console . error ( 'Drift snippet included twice.' )
2726 )
2827 }
@@ -41,22 +40,17 @@ const loadScript = () => {
4140 'off' ,
4241 'on'
4342 ] ) ,
44- //eslint-disable-next-line @typescript-eslint/no-explicit-any
4543 ( t . factory = function ( e : any ) {
4644 return function ( ) {
47- //eslint-disable-next-line prefer-rest-params
4845 const n = Array . prototype . slice . call ( arguments )
4946 return n . unshift ( e ) , t . push ( n ) , t
5047 }
5148 } ) ,
52- //eslint-disable-next-line @typescript-eslint/no-explicit-any
5349 t . methods . forEach ( function ( e : any ) {
5450 t [ e ] = t . factory ( e )
5551 } ) ,
56- //eslint-disable-next-line @typescript-eslint/no-explicit-any
5752 ( t . load = function ( t : any ) {
5853 const e = 3e5 ,
59- //eslint-disable-next-line @typescript-eslint/no-explicit-any
6054 n = Math . ceil ( ( new Date ( ) as any ) / e ) * e ,
6155 o = document . createElement ( 'script' )
6256 ; ( o . type = 'text/javascript' ) ,
@@ -68,38 +62,39 @@ const loadScript = () => {
6862 } )
6963 }
7064 } ) ( )
65+
66+ return true
7167}
72- /* eslint: enable */
68+ /* eslint- enable */
7369
7470const load = ( {
7571 providerKey,
7672 setState
7773} : {
7874 providerKey : string
7975 setState : ( state : State ) => void
80- } ) : void => {
81- loadScript ( )
82- window . drift . load ( providerKey )
83- window . drift . SNIPPET_VERSION = '0.3.1'
84- window . drift . on ( 'ready' , ( ) => {
85- setState ( 'open' )
86- setTimeout ( ( ) => setState ( 'complete' ) , 2000 )
87- } )
76+ } ) : boolean => {
77+ const loaded = loadScript ( )
78+
79+ // Continue as long as drift hasn’t already been initialised.
80+ if ( loaded ) {
81+ window . drift . load ( providerKey )
82+ window . drift . SNIPPET_VERSION = '0.3.1'
83+ window . drift . on ( 'ready' , ( ) => {
84+ setState ( 'complete' )
85+ } )
86+ }
87+
88+ return loaded
8889}
8990
9091const open = ( ) : void =>
9192 window . drift . on ( 'ready' , ( api : { showWelcomeMessage : ( ) => void } ) =>
9293 api . showWelcomeMessage ( )
9394 )
9495
95- const close = ( ) : void =>
96- window . drift . on ( 'ready' , ( api : { hideWelcomeMessage : ( ) => void } ) =>
97- api . hideWelcomeMessage ( )
98- )
99-
10096export default {
10197 domain,
10298 load,
103- open,
104- close
99+ open
105100}
0 commit comments