import { request } from 'obsidian' ; import type { Synonym , SynonymProvider } from "src/integrations/types" ; export class SynonymoSynonymAPI implements SynonymProvider { public name = "Synonymo" ; public url = "http://www.synonymo.fr/" ; public supportedLanguages : string [ ] = [ "fr" ] ; offline = false ; API_END_POINT = 'http://www.synonymo.fr/synonyme/' ; param query returns constructRequest ( query ) { return this . API_END_POINT + query ; } async requestSynonyms ( query ) { const synonyms = [ ] ; let result ; try { result = await request ( { url : this . constructRequest ( query ) } ) ; } catch ( error ) { return Promise . reject ( error ) ; } if ( ! result ) { return Promise . reject ( "Word doesnt exist in this Dictionary" ) ; } const parser = new DOMParser ( ) ; const doc = parser . parseFromString ( result , 'text/html' ) ; const x = doc . body . getElementsByClassName ( "fiche" ) . item ( 0 ) . getElementsByClassName ( "word" ) ; for ( let i = 0 ; i < x . length ; i ++ ) { synonyms . push ( { word : x . item ( i ) . textContent } ) ; } return synonyms ; } }