MCPcopy Index your code
hub / github.com/dataease/SQLBot / expposeGlobalMethods

Function expposeGlobalMethods

frontend/public/assistant.js:760–852  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

758 }
759 }
760 function expposeGlobalMethods(id) {
761 window.sqlbot_assistant_handler[id]['setOnline'] = (online) => {
762 if (online != null && typeof online != 'boolean') {
763 throw new Error('The parameter can only be of type boolean')
764 }
765 const iframe = document.getElementById(`sqlbot-assistant-chat-iframe-${id}`)
766 if (iframe) {
767 const url = iframe.src
768 const eventName = 'sqlbot_assistant_event'
769 const params = {
770 busi: 'setOnline',
771 online,
772 eventName,
773 messageId: id,
774 }
775 const contentWindow = iframe.contentWindow
776 contentWindow.postMessage(params, url)
777 }
778 }
779 window.sqlbot_assistant_handler[id]['refresh'] = (online, userFlag) => {
780 if (online != null && typeof online != 'boolean') {
781 throw new Error('The parameter can only be of type boolean')
782 }
783 const iframe = document.getElementById(`sqlbot-assistant-chat-iframe-${id}`)
784 if (iframe) {
785 const url = iframe.src
786 let new_url = updateParam(url, 't', Date.now())
787 if (online != null) {
788 new_url = updateParam(new_url, 'online', online)
789 }
790 if (userFlag != null) {
791 new_url = updateParam(new_url, 'userFlag', userFlag)
792 }
793 iframe.src = 'about:blank'
794 setTimeout(() => {
795 iframe.src = new_url
796 }, 500)
797 }
798 }
799 window.sqlbot_assistant_handler[id]['destroy'] = () => {
800 const sqlbot_root_id = 'sqlbot-assistant-root-' + id
801 const container_div = document.getElementById(sqlbot_root_id)
802 if (container_div) {
803 const root_div = container_div.parentNode
804 if (root_div?.parentNode) {
805 root_div.parentNode.removeChild(root_div)
806 }
807 }
808
809 const scriptDom = document.getElementById(`sqlbot-assistant-float-script-${id}`)
810 if (scriptDom) {
811 scriptDom.parentNode.removeChild(scriptDom)
812 }
813 const propName = script_id_prefix + id + '-state'
814 if (window[propName]) {
815 delete window[propName]
816 }
817 delete window.sqlbot_assistant_handler[id]

Callers 1

initFunction · 0.85

Calls 1

updateParamFunction · 0.85

Tested by

no test coverage detected