diff --git a/www/activities/foodlist/js/open-food-facts.js b/www/activities/foodlist/js/open-food-facts.js index 84051a8ad..4879c1960 100644 --- a/www/activities/foodlist/js/open-food-facts.js +++ b/www/activities/foodlist/js/open-food-facts.js @@ -23,10 +23,16 @@ app.OpenFoodFacts = { //Build search string let url; + let usdaEnabled = app.Settings.get("integration", "usda") && (app.Settings.get("integration", "usda-key") != ""); + let barcodeOnlySearch = (app.Settings.get("integration", "off-only-barcode") || false) && usdaEnabled; + // If query is a number, assume it's a barcode - if (isNaN(query)) + if (isNaN(query)){ + // If the user only wants to use OFF for barcode scans return empty list and hope the next provider has the data + if (barcodeOnlySearch) + return resolve(undefined); url = "https://world.openfoodfacts.org/cgi/search.pl?search_terms=" + encodeURIComponent(query) + "&search_simple=1&page_size=50&sort_by=unique_scans_n&action=process&json=1"; - else + } else url = "https://world.openfoodfacts.org/api/v0/product/" + encodeURIComponent(query) + ".json"; //Get country name diff --git a/www/activities/settings/js/settings.js b/www/activities/settings/js/settings.js index 60ef5858c..5378b7cde 100644 --- a/www/activities/settings/js/settings.js +++ b/www/activities/settings/js/settings.js @@ -756,7 +756,8 @@ app.Settings = { "search-language": "Default", "search-country": "All", "upload-country": "Auto", - usda: false + usda: false, + "off-only-barcode": false }, tts: { "speed": 1, diff --git a/www/activities/settings/views/integration.html b/www/activities/settings/views/integration.html index a46fc4d7c..0b0d5352e 100644 --- a/www/activities/settings/views/integration.html +++ b/www/activities/settings/views/integration.html @@ -795,6 +795,20 @@ +
  • +
    +
    +
    Barcode Only Search
    +
    + +
    +
    +
    +
  • +
  • U.S. DEPARTMENT OF AGRICULTURE