( show_debug_cursor?: boolean, logger?: (...args: any[]) => void )
| 160 | private static currentPage: RemotePage | undefined = undefined; |
| 161 | |
| 162 | static async getRemotePage( |
| 163 | show_debug_cursor?: boolean, |
| 164 | logger?: (...args: any[]) => void |
| 165 | ): Promise<RemotePage | undefined> { |
| 166 | if (this.currentPage) { |
| 167 | return this.currentPage; |
| 168 | } |
| 169 | /** |
| 170 | * OCS桌面端后端无法拦截 GM_xmlhttpRequest ,所以这里使用 fetch 请求动作执行,然后后端根据key判断是否允许执行 |
| 171 | */ |
| 172 | if (!this.authToken) { |
| 173 | try { |
| 174 | this.authToken = await request('http://localhost:15319/get-actions-key', { |
| 175 | type: 'GM_xmlhttpRequest', |
| 176 | method: 'get', |
| 177 | responseType: 'text' |
| 178 | }); |
| 179 | this.currentPage = this.createRemotePage(this.authToken, { show_debug_cursor, logger }); |
| 180 | return this.currentPage; |
| 181 | } catch (e) { |
| 182 | console.log(e); |
| 183 | return undefined; |
| 184 | } |
| 185 | } else { |
| 186 | this.currentPage = this.createRemotePage(this.authToken, { show_debug_cursor, logger }); |
| 187 | return this.currentPage; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | private static createRemotePage( |
| 192 | authToken: string, |
no test coverage detected