neptune-web commited on
Commit
fdfca8c
·
1 Parent(s): 1f154fd

[bugfix #111] no activity with the prompt in extension

Browse files
Files changed (1) hide show
  1. Extension/src/pages/Panel/Panel.jsx +85 -80
Extension/src/pages/Panel/Panel.jsx CHANGED
@@ -21,7 +21,7 @@ const confs = {
21
  const URL_BASE = 'https://ttt246-brain.hf.space/'
22
  const URL_SEND_NOTIFICATION = URL_BASE + 'sendNotification'
23
  const URL_BROWSER_ITEM = URL_BASE + 'browser/item'
24
- const URL_ASK_WEBSITE = URL_BASE + 'browser/ask_website'
25
 
26
  let prompt = ""
27
 
@@ -93,85 +93,86 @@ const Panel = () => {
93
  }
94
  setQuestion("")
95
 
96
- const data = sendRequest(params, URL_SEND_NOTIFICATION)
97
- if (data.result === undefined || data.result == null) {
98
- return
99
- }
100
-
101
- try {
102
- if (data.result.program === undefined || data.result.program == null) {
103
- addMessage(data.result, false)
104
  return
105
  }
106
 
107
- let page = 0
108
- const currentUrl = window.location.href
109
-
110
- switch (data.result.program) {
111
- case "browser":
112
- addMessage(data.result.content, false)
113
- window.location.assign(data.result.content)
114
- break
115
- case 'open_tab':
116
- addMessage("open tab", false)
117
- window.open('https://google.com/search?q=', '_blank', 'noreferrer')
118
- break
119
- case 'open_tab_search':
120
- addMessage("open tab and search", false)
121
- window.open('https://google.com/search?q=' + data.result.content, '_blank', 'noreferrer')
122
- break
123
- case 'close_tab':
124
- addMessage("close tab", false)
125
- window.close()
126
- break
127
- case 'previous_page':
128
- if (page === 0) {
129
- page = 0
130
- } else {
131
- page -= 10
132
- }
133
-
134
- addMessage("go to previous page", false)
135
- window.location.assign(currentUrl + '&start=' + page)
136
- break
137
- case 'next_page':
138
- page += 10
139
-
140
- addMessage("go to next page", false)
141
- window.location.assign(currentUrl + '&start=' + page)
142
- break
143
- case 'scroll_up':
144
- addMessage("scroll up", false)
145
- window.scrollBy(0, -300)
146
- break
147
- case 'scroll_down':
148
- addMessage("scroll down", false)
149
- window.scrollBy(0, 300)
150
- break
151
- case 'scroll_top':
152
- addMessage("scroll to top", false)
153
- window.scrollTo(0, 0)
154
- break
155
- case 'scroll_bottom':
156
- addMessage("scroll to bottom", false)
157
- window.scrollTo(0, document.body.scrollHeight)
158
- break
159
- case 'message':
160
- addMessage(data.result.content, false)
161
- break
162
- case 'select_item_detail_info':
163
- addMessage("I need more detail info to select item", false)
164
- selectItem()
165
- break
166
- case 'ask_website':
167
- askAboutCurrentWebsite()
168
- break
169
- default:
170
- break
 
 
 
 
 
 
 
 
 
171
  }
172
- } catch (e) {
173
- throw e
174
- }
175
  }
176
 
177
  const selectItem = async () => {
@@ -180,8 +181,10 @@ const Panel = () => {
180
  "prompt": prompt,
181
  "items": scrapeATags()
182
  }
183
- const data = sendRequest(params, URL_BROWSER_ITEM)
184
- window.open(data.result.content, '_blank', 'noreferrer')
 
 
185
  }
186
 
187
  const askAboutCurrentWebsite = async () => {
@@ -190,8 +193,10 @@ const Panel = () => {
190
  "prompt": prompt,
191
  "items": scrapeWebsites()
192
  }
193
- const data = sendRequest(params, URL_ASK_WEBSITE)
194
- addMessage(data.result.content, false)
 
 
195
  }
196
 
197
  /*
 
21
  const URL_BASE = 'https://ttt246-brain.hf.space/'
22
  const URL_SEND_NOTIFICATION = URL_BASE + 'sendNotification'
23
  const URL_BROWSER_ITEM = URL_BASE + 'browser/item'
24
+ const URL_ASK_WEBSITE = URL_BASE + 'browser/ask'
25
 
26
  let prompt = ""
27
 
 
93
  }
94
  setQuestion("")
95
 
96
+ sendRequest(params, URL_SEND_NOTIFICATION).then(data => {
97
+ if (data.result === undefined || data.result == null) {
 
 
 
 
 
 
98
  return
99
  }
100
 
101
+ try {
102
+ if (data.result.program === undefined || data.result.program == null) {
103
+ addMessage(data.result, false)
104
+ return
105
+ }
106
+
107
+ let page = 0
108
+ const currentUrl = window.location.href
109
+
110
+ switch (data.result.program) {
111
+ case "browser":
112
+ addMessage(data.result.content, false)
113
+ window.location.assign(data.result.content)
114
+ break
115
+ case 'open_tab':
116
+ addMessage("open tab", false)
117
+ window.open('https://google.com/search?q=', '_blank', 'noreferrer')
118
+ break
119
+ case 'open_tab_search':
120
+ addMessage("open tab and search", false)
121
+ window.open('https://google.com/search?q=' + data.result.content, '_blank', 'noreferrer')
122
+ break
123
+ case 'close_tab':
124
+ addMessage("close tab", false)
125
+ window.close()
126
+ break
127
+ case 'previous_page':
128
+ if (page === 0) {
129
+ page = 0
130
+ } else {
131
+ page -= 10
132
+ }
133
+
134
+ addMessage("go to previous page", false)
135
+ window.location.assign(currentUrl + '&start=' + page)
136
+ break
137
+ case 'next_page':
138
+ page += 10
139
+
140
+ addMessage("go to next page", false)
141
+ window.location.assign(currentUrl + '&start=' + page)
142
+ break
143
+ case 'scroll_up':
144
+ addMessage("scroll up", false)
145
+ window.scrollBy(0, -300)
146
+ break
147
+ case 'scroll_down':
148
+ addMessage("scroll down", false)
149
+ window.scrollBy(0, 300)
150
+ break
151
+ case 'scroll_top':
152
+ addMessage("scroll to top", false)
153
+ window.scrollTo(0, 0)
154
+ break
155
+ case 'scroll_bottom':
156
+ addMessage("scroll to bottom", false)
157
+ window.scrollTo(0, document.body.scrollHeight)
158
+ break
159
+ case 'message':
160
+ addMessage(data.result.content, false)
161
+ break
162
+ case 'select_item_detail_info':
163
+ addMessage("I need more detail info to select item", false)
164
+ selectItem()
165
+ break
166
+ case 'ask_website':
167
+ askAboutCurrentWebsite()
168
+ break
169
+ default:
170
+ break
171
+ }
172
+ } catch (e) {
173
+ throw e
174
  }
175
+ })
 
 
176
  }
177
 
178
  const selectItem = async () => {
 
181
  "prompt": prompt,
182
  "items": scrapeATags()
183
  }
184
+ sendRequest(params, URL_BROWSER_ITEM).then(data => {
185
+ window.open(data.result.content, '_blank', 'noreferrer')
186
+ }).catch(err => {
187
+ })
188
  }
189
 
190
  const askAboutCurrentWebsite = async () => {
 
193
  "prompt": prompt,
194
  "items": scrapeWebsites()
195
  }
196
+ sendRequest(params, URL_ASK_WEBSITE).then(data => {
197
+ addMessage(data.result.content, false)
198
+ }).catch(err => {
199
+ })
200
  }
201
 
202
  /*