1- // @refresh reload
21import * as wanakana from "wanakana" ;
32import {
43 createSignal ,
@@ -32,41 +31,23 @@ type LastConversion = {
3231 end : number ;
3332} ;
3433
35- const JISHO_PROXY_BASE = import . meta. env . PROD
36- ? "https://cors-anywhere.com/"
37- : "https://thingproxy.freeboard.io/fetch/" ;
34+ const JISHO_PROXY_BASE = "https://cors-anywhere.com/" ;
3835
3936async function fetchKanjiFromJisho ( reading : string ) : Promise < string [ ] > {
40- if ( ! reading ) return [ ] ;
41-
42- const jishoBaseUrl = "jisho.org/api/v1/search/words?keyword=" ;
43- const jishoFullUrl = jishoBaseUrl + encodeURIComponent ( reading ) ;
44-
45- let proxyUrl : string ;
46-
47- if ( import . meta. env . PROD ) {
48- proxyUrl = JISHO_PROXY_BASE + jishoFullUrl ;
49- } else {
50- const fullJishoTarget =
51- "https://jisho.org/api/v1/search/words?keyword=" + encodeURIComponent ( reading ) ;
52- proxyUrl = JISHO_PROXY_BASE + "?url=" + encodeURIComponent ( fullJishoTarget ) ;
37+ if ( ! reading ) {
38+ return [ ] ;
5339 }
5440
55- try {
56- const fetchOptions : RequestInit = { } ;
41+ const jishoTargetUrl =
42+ "https://jisho.org/api/v1/search/words?keyword=" + encodeURIComponent ( reading ) ;
5743
58- if ( ! import . meta. env . PROD ) {
59- fetchOptions . headers = {
60- "X-Requested-With" : "XMLHttpRequest" ,
61- } ;
62- }
44+ const proxyUrl = JISHO_PROXY_BASE + jishoTargetUrl ;
6345
64- const res = await fetch ( proxyUrl , fetchOptions ) ;
46+ try {
47+ const res = await fetch ( proxyUrl ) ;
6548
6649 if ( ! res . ok ) {
67- console . error (
68- `Error fetching from proxy (${ import . meta. env . PROD ? "CORS Anywhere" : "Thingproxy" } ): ${ res . status } ${ res . statusText } `
69- ) ;
50+ console . error ( `Error fetching from CORS Anywhere proxy: ${ res . status } ${ res . statusText } ` ) ;
7051 try {
7152 const errorText = await res . text ( ) ;
7253 console . error ( "Proxy error response:" , errorText ) ;
@@ -75,10 +56,16 @@ async function fetchKanjiFromJisho(reading: string): Promise<string[]> {
7556 }
7657 return [ ] ;
7758 }
59+
7860 const json = ( await res . json ( ) ) as JishoResponse ;
79- if ( ! json ?. data ) return [ ] ;
80- const set = new Set ( json . data . map ( ( e ) => e . japanese [ 0 ] . word || e . japanese [ 0 ] . reading ) ) ;
81- return Array . from ( set ) ;
61+
62+ if ( ! json ?. data ) {
63+ return [ ] ;
64+ }
65+
66+ const uniqueWords = new Set ( json . data . map ( ( e ) => e . japanese [ 0 ] . word || e . japanese [ 0 ] . reading ) ) ;
67+
68+ return Array . from ( uniqueWords ) ;
8269 } catch ( error ) {
8370 console . error ( "Error in fetchKanjiFromJisho:" , error ) ;
8471 return [ ] ;
@@ -123,7 +110,6 @@ export function IMEField() {
123110 if ( ta ) wanakana . unbind ( ta ) ;
124111 } ) ;
125112
126- // reset menu when lookupReading changes
127113 createEffect ( ( ) => {
128114 suggestions ( ) ;
129115 itemRefs = [ ] ;
@@ -190,7 +176,6 @@ export function IMEField() {
190176 return ;
191177 }
192178
193- // backspace to undo last conversion
194179 const lc = lastConversion ( ) ;
195180 if (
196181 e . key === "Backspace" &&
0 commit comments