diff --git a/popup/popup.js b/popup/popup.js index 4c28e09..db73642 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -81,8 +81,8 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome') // Browse tab UI.prototype.initView = async function () { // Word input 2 : text field - // this.searchWidget = new SearchWidget( { placeholder: banana.i18n("si-popup-browse-placeholder", Object.keys( _backgroundPage.records ).length ) } ); - // this.searchWidget.setRecords( _backgroundPage.records ); + this.searchWidget = new SearchWidget( { placeholder: banana.i18n("si-popup-browse-placeholder", Object.keys( _backgroundPage.records ).length ) } ); + this.searchWidget.setRecords( _backgroundPage.records ); var searchButton = new OO.ui.ButtonWidget( { icon:"search", label: banana.i18n("si-popup-browse-label"), @@ -90,8 +90,7 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome') title: banana.i18n("si-popup-browse-icon") } ); - // var searchLayout = new OO.ui.ActionFieldLayout( this.searchWidget, searchButton, { - var searchLayout = new OO.ui.ActionFieldLayout( searchButton, { + var searchLayout = new OO.ui.ActionFieldLayout( this.searchWidget, searchButton, { align: 'top', label: banana.i18n("si-popup-browse-label"), invisibleLabel: true, @@ -126,7 +125,7 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome') // refresh the view each time a search is made searchButton.on( 'click', this.changeView.bind( this ) ); - // this.searchWidget.lookupMenu.on( 'choose', this.changeView.bind( this ) ); + this.searchWidget.lookupMenu.on( 'choose', this.changeView.bind( this ) ); }; UI.prototype.changeView = async function (text) { @@ -137,7 +136,7 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome') const [_word,_files] = await sendMessageUp("normalizeWordAndReturnFiles",text); this.coreContent.refresh(_word, _files); - // this.searchWidget.setValue( _word ); + this.searchWidget.setValue( _word ); this.coreContent.getContainer().show(); this.addHistory(_word); }; @@ -199,16 +198,16 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome') /* Sign Language picker */ // Data var items = []; - // _signLanguages = _backgroundPage.signLanguages; - // console.log("148 signLanguages", _signLanguages ) - // for (var i=0;i<_signLanguages.length;i++ ) { - // lang = _signLanguages[i]; - // console.log("151 lang", lang ) // #136 - // items.push( new OO.ui.MenuOptionWidget( { - // data: lang.wdQid, // qid - // label: lang.labelNative, // sign language name (en) - // } ) ); - // } + _signLanguages = _backgroundPage.signLanguages; + console.log("148 signLanguages", _signLanguages ) + for (var i=0;i<_signLanguages.length;i++ ) { + lang = _signLanguages[i]; + console.log("151 lang", lang ) // #136 + items.push( new OO.ui.MenuOptionWidget( { + data: lang.wdQid, // qid + label: lang.labelNative, // sign language name (en) + } ) ); + } // Layout signLanguageDropdown = new OO.ui.DropdownWidget( { label: banana.i18n("si-popup-settings-signlanguage-dropdown"), diff --git a/sw.js b/sw.js index ef569a7..4f82365 100644 --- a/sw.js +++ b/sw.js @@ -479,21 +479,14 @@ async function setState(value) { async function getSignLanguagesWithVideos() { try { - const response = await fetch(sparqlEndpoints.lingualibre.url, { - method: "POST", - body: JSON.stringify({ - format: "json", - query: sparqlSignLanguagesQuery, - }), - }); - + const response = await fetch(`${sparqlEndpoints.lingualibre.url}/?query=${encodeURI(sparqlSignLanguagesQuery)}&format=json`); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); // Await the parsed JSON response - const signLanguages = []; + let signLanguages = []; for (let i = 0; i < data.results.bindings.length; i++) { const signLanguageRaw = data.results.bindings[i]; const signLanguage = { @@ -515,9 +508,7 @@ async function setState(value) { // Loading all vidéos of a given sign language. Format: // returns format: { word: { filename: url, speaker: name }, ... }; - async function getAllRecords(signLanguage) { - // response = await $.post( sparqlEndpoints.lingualibre.url, { format: 'json', query: sparqlSignVideosQuery.replace( '$(lang)', signLanguage ) } ); - + async function getAllRecords(signLanguage) { // Using Fetch API since service_worker cant access DOM and hence cant use jquery var i, @@ -529,13 +520,7 @@ async function setState(value) { // state = "loading"; state = await setState("loading"); - response = await fetch(sparqlEndpoints.lingualibre.url, { - method: "POST", - body: JSON.stringify({ - format: "json", - query: sparqlSignVideosQuery.replace("$(lang)", signLanguage), - }), - }); + response = await fetch(`${sparqlEndpoints.lingualibre.url}/?query=${encodeURI(sparqlSignVideosQuery.replace('$(lang)', signLanguage))}&format=json`); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); @@ -802,11 +787,11 @@ async function setState(value) { await getStoredParam("choosepanels"); let signLanguage = await getStoredParam("signLanguage"); - // signLanguages = await getSignLanguagesWithVideos(); + signLanguages = await getSignLanguagesWithVideos(); let uiLanguage = await getStoredParam("uiLanguage"); console.log("supportedUiLanguages", supportedUiLanguages); uiLanguages = supportedUiLanguages; - // records = await getAllRecords( signLanguage ); + records = await getAllRecords( signLanguage ); // state = "ready"; state = await setState("ready"); @@ -820,7 +805,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.command === "getBackground") { // persisted the state inside chrome.storage.local but will get to that later console.log(state); - const a = {state,params,uiLanguages}; - sendResponse(a); + const extensionData = {state,params,uiLanguages,records,signLanguages}; + sendResponse(extensionData); } }); \ No newline at end of file